Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

ScriptRunner: Keep request alive during a script that takes a long time to finish

Ricardo Martinez
Contributor
September 2, 2019

I have a script that makes a rest api call to another application.
The script then waits for the call to finish.

Meaning the script executes the call then sleeps for 5 seconds then asks if it finished and keeps waiting 5 seconds until it does.

Sometimes the whole execution of the script can take more than 1 hour.

Jira is under a NGINX and this proxy closes the connection after a time out. When this happens the script keeps executing but the console finishes and doesn't come up with results.

Is there a way for the script to keep the connection open while waiting?

Oversimplified example:

while(OtherRestCallIsNotFinished)

{ sleep(1000) keepConnectionOpenWithProxy() }

1 answer

1 accepted

0 votes
Answer accepted
Ilya Turov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 2, 2019

What about storing the results into a separate file? 

Or simply logging them and retrieving this way.

Ricardo Martinez
Contributor
September 2, 2019

I already do that, but I do not know when the whole script is finished, so I can go to the file and check it.

 

It would be much better to keep the connection open until it does.

Ilya Turov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 2, 2019

Guess you can add a piece of code that will notify you via email after it's done :)

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.mail.Email
import com.atlassian.mail.queue.SingleMailQueueItem

def email = new Email("someuser@example.com")
email.setSubject("all done")
email.setBody("")
email.setMimeType("text/html") // for messages with an html body

SingleMailQueueItem item = new SingleMailQueueItem(email)
ComponentAccessor.mailQueue.addItem(item)
Ricardo Martinez
Contributor
September 4, 2019

The email alternative is a good idea, I have actually just implemented it.

 

A way to know when the script finished in case the console closed the connection.

 

I got a response from Adaptavist (ScriptRunner) about this issue.

https://productsupport.adaptavist.com/browse/SRPLAT-3

Basically it is an open request to have a progress response on the script.

 

In the meantime an email sounds like a good idea to get notified when it finishes.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Upcoming Apps & Integrations Events