Invocation limits for a forge App - (Maximum runtime seconds = 25)

Hi Team,
I am trying optimize my code in the forge app to have 25 seconds as Total runtime permitted before the app is stopped.
To split long running tasks into several small workers and place them on the Async Queue to be run later, Async event API is used in the code.

Getting below error even after implementing queue:

“Function result will not be returned to the Forge platform, as the function did not complete within 25 seconds. In invocations outside tunnel, functions that exceed the time limit are terminated.”
Also code runs again and again in a loop showing same message above.

Kindly provide assistance to resolve the blocker.

Here is the sample code: ( as per documentation):
manifest.yml:

modules:
  trigger:
    - key: queue-hello-world-app-hello-world
      function: main
      events:
        - avi:jira:updated:issue
  consumer:
    - key: queue-consumer
      # Name of the queue for which this consumer will be invoked
      queue: queue-name
      resolver:
        function: consumer-function
        # resolver function to be called with payload
        method: event-listener
  function:
    - key: main
      handler: index.run
    - key: consumer-function
      handler: consumer.handler
app:
  id: ari:cloud:ecosystem::app/79d4ef01-07b6*********************
permissions:
  scopes:
    - read:jira-work

index.js:

import { Queue } from '@forge/events';
export async function run(event, context) {
	
	const queue = new Queue({ key: 'queue-name' });
	await queue.push(["Payload 1", "Payload 2", "Payload 3"]);
        
}

consumer.js:

import Resolver from "@forge/resolver";
const resolver = new Resolver();

function sleep(ms) {
	return new Promise(resolve => setTimeout(resolve, ms));
  }

resolver.define("event-listener", async ({ payload, context }) => {
console.log(payload)
await sleep(100000);  // sleep set to 1 min 
});

export const handler = resolver.getDefinitions();

Hi @chaitrap_g ,

Welcome to the Atlassian Developer Community.

We’ve recently announced that the runtime limit has been increased to 55 seconds for async event invocations.

I’ve created an example app to explain how to take advantage of this increased limit so hopefully this helps.

Regards,
Dugald

3 Likes