I have created lifecycle trigger which would trigger one function on installation of forge app into jira cloud.
I want to create some custom fields on installation of the app. So I have created one function and add that function as lifecycle trigger in manifest.yml file. From this function I am creating one Queue and pushing events to the queue to create custom fields but the behavior of the function is inconsistent as it does not always invoke the queue resolver. On installation trigger calls a function but events pushed to the queue are not being resolved.
Below is basic structure of my function.
mainfest.yml
modules:
function:
- key: custom-handler
handler: index.customizationHandler
- key: install-handler
handler: index.initializeCustomization
trigger:
- key: lifecycle-trigger
function: install-handler
events:
- avi:forge:installed:app
- avi:forge:upgraded:app
consumer:
- key: custom-queue-one
queue: custom-one
resolver:
function: custom-handler
method: createCustomFields
permissions:
scopes:
- manage:jira-project
- write:jira-work
- manage:jira-configuration
- storage:app
- read:jira-work
index.js file
import Resolver from "@forge/resolver";
import { Queue } from "@forge/events";
const resolver = new Resolver();
export const initializeCustomization = async () => {
const fields = ["custom1","custom2","custom3"]
fields.forEach(async (item) => {
const queue = new Queue({ key: "customize-one" });
await queue.push(item);
});
};
resolver.define("createCustomFields", async ({payload,context}) => {
const res = await createField(payload);
console.log(res);
});
export const customizationHandler = resolver.getDefinitions();