How to handle invocation timeout

I am building a Forge application for Jira in which I want to fetch data at regular intervals. Based on the fetched data, I am creating Jira issues and setting a scheduledTrigger to invoke my function. Now, I see that the function invocation time is 25 seconds. I want to know how I can handle this scenario because I am scheduling function invocations, and that function fetches data and creates Jira issues, which is taking more time than expected. How can I handle this situation?
Thanks.

I also want to know if we can receive any exception or error because I noticed that if my function invocation exceeds 25 seconds, it stops without any log or exception. In my code, I have caught the exception.
Can someone share the documentation or any resources to handle this scenario?

Hi Parthpuri,

We just launched 15min Async Invocations that should work for your needs [https://developer.atlassian.com/changelog/#CHANGE-2288 - Forge functions can now run for up to 15 mins (900 seconds) when processing async events]

Also within those Async events you can also check how much time you have left via: https://developer.atlassian.com/changelog/#CHANGE-2277 - API to get remaining execution time for a Forge function (invocationRemainingTimeInMillis)

Let me know if that helps.

Hi Benny, As I am new to this technology, could you guide me on how to use this async consumer in my application? I already have two functions in my application. One triggers when the user enters a configuration and stores it in a key-value store, and the other runs hourly using scheduledTrigger to check if the configuration is present in the key-value store. If the configuration is present, it starts fetching data from a third-party application. Now, I want to increase the time for the function set in scheduledTrigger. How can I set up the consumer as well?

No worries at all, the following documentation should help you: https://developer.atlassian.com/platform/forge/runtime-reference/async-events-api/

Just make sure if you want to use 15min invocations, to set timeoutSeconds to 900.

Let me know how you go.

Yes, I have already checked that document. However, I don’t understand how this will work. I currently have a function running via scheduledTrigger. If I fetch data using that function and place it in a queue, the consumer will process the data, which takes about 15 minutes. But will my earlier function, which is triggered by scheduledTrigger, also run for 15 minutes while it fetches the data?

Please let me know if I misunderstood anything.

So the schedule trigger is a max 25s Lambda; that would kick off your Async events [multiple if needed] (max 15min, can be shorter). The schedule trigger would end as soon as the code block has run.

Okay, thanks for the explanation. So, what I understand is that I need to create two functions: one for scheduledTrigger and another as a consumer. Using the first function, I can push third-party APIs and credentials to the queue, and the consumer will execute the API and push the next page details to the queue. And the consumer will run even if the first function has finished execution or timed out.

Correct me if I am wrong. Thanks again.

Hi Parthpuri,

Conceptually you have it correct.

Schedule trigger runs → You add your tasks to the async queue
Then the Async consumer kicks off and processes your jobs.

Good luck in building your Forge App :smiley:

1 Like