Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const handler = async ({ task, taskService }) => {
// get task variable 'defaultScore'
const defaultScore = task.variables.get("defaultScore");
// set process variable 'creditScores'
const creditScores = [defaultScore, 9, 1, 4, 10];
const processVariables = new Variables()
.set("creditScores", creditScores)
.set("bar", new Date());
// complete the task
try {
await taskService.complete(task, processVariables);
console.log("I completed my task successfully!!");
} catch (e) {
console.error(`Failed completing my task, ${e}`);
}
};
client.subscribe("invoiceCreator", async function({ task, taskService }) {
// Put your business logic
// complete the task
const date = new Date();
const invoice = await new File({ localPath: "./assets/invoice.txt" }).load();
const minute = date.getMinutes();
const variables = new Variables().setAll({ invoice, date });
// check if minute is even
if (minute % 2 === 0) {
// for even minutes, store variables in the process scope
await taskService.complete(task, variables);
} else {
// for odd minutes, store variables in the task local scope
await taskService.complete(task, null, variables);
}
});
client.subscribe("customer-credit", async function({ task, taskService }) {
var remainingAmount = 0;
if (Math.random() > 0.3) {
remainingAmount = 15;
}
const processVariables = new Variables();
processVariables.set("remainingAmount", remainingAmount);
console.log('[%s] done for process instance %s with remainingAmount=%s', task.topicName, task.processInstanceId, remainingAmount);
await taskService.complete(task, processVariables);
});
client.subscribe("customer-credit", async function({ task, taskService }) {
var remainingAmount = 0;
if (Math.random() > 0.3) {
remainingAmount = 15;
}
const processVariables = new Variables();
processVariables.set("remainingAmount", remainingAmount);
console.log('[%s] done for process instance %s with remainingAmount=%s', task.topicName, task.processInstanceId, remainingAmount);
await taskService.complete(task, processVariables);
});