By default, async event consumers time out after 55 seconds. Use cases that required longer computation have had to rely on breaking the task into multiple steps or batches, and queuing multiple events to do the work.
You can now configure a timeout of up to 900 seconds (15 minutes) which will allow many such use cases to be performed in a single invocation.
Imagine you are developing an application that generates detailed reports from Jira issues. This process can be time-consuming, especially if you are aggregating data from multiple projects and applying complex calculations. The Long-Running Compute feature allows you to handle these tasks efficiently without running into timeout issues.
This tutorial assumes you're already familiar with developing on Forge and the Async Events API.
Before you start, ensure you have the following:
Follow the prompts to set up your application. Name your app and choose the template appropriate to the type of app you are creating. For the purposes of this tutorial the1 2forge create
blank
template will work fine. If you intend to extend this example with a UI to trigger the long-running function you can select a template from the UI Kit category.1 2cd your-app-name
1 2permissions: scopes: - read:jira-work
generateReport.js
:
1 2import { invoke } from '@forge/api'; export const handler = async (event) => { const { projectKey } = event; // Simulate a long-running task const reportData = await generateReport(projectKey); return { statusCode: 200, body: JSON.stringify(reportData), }; }; const generateReport = async (projectKey) => { const issues = await fetchIssuesFromJira(projectKey); // Perform complex calculations and aggregations const report = performCalculations(issues); return report; }; const fetchIssuesFromJira = async (projectKey) => { // Simulate a delay for fetching data await new Promise(resolve => setTimeout(resolve, 5000)); // Return mock data return [ { id: 1, status: 'Done', points: 5 }, { id: 2, status: 'In Progress', points: 3 }, ]; }; const performCalculations = (issues) => { // Aggregate data const totalPoints = issues.reduce((sum, issue) => sum + issue.points, 0); return { totalPoints }; };
manifest.yml
:
Register the new function in your manifest.yml
:
1 2modules: function: - key: generate-report handler: generateReport.handler timeoutSeconds: 900
1 2forge deploy
1 2forge install
You can invoke the long-running function from your frontend or another backend service.
Long-running functions allow Forge developers to handle complex and time-consuming tasks efficiently. By following this tutorial, you have learned how to set up a realistic use case for generating reports from Jira data.
Rate this page: