const { Client, logger } = require("camunda-external-task-client-js");
const { Variables } = require("camunda-external-task-client-js");
// configuration for the Client:
// - 'baseUrl': url to the Process Engine
// - 'logger': utility to automatically log important events
const config = { baseUrl: "http://localhost:8080/engine-rest", use: logger };
// create a Client instance with custom configuration
const client = new Client(config);
// susbscribe to the topic: 'creditScoreChecker'
client.subscribe("msg-topic", async function({ task, taskService }) {
console.log(" in order processing service worker");
//const processVariables = new Variables();
//processVariables.set("processretry", 'yes');
let rand=Math.random();
console.log("rand variable is ",rand);
await taskService.complete(task);
// Put your business logic
// complete the task
});
There is some rule, I use everywhere with parallel processing: Set async after flag on every last task of parallel threads, before parallel joint.
This rule leads, that your own code always be successful, because commit leads to stop before join. And you tell engine… Try yourself solve this, not through my own code.
Actually engine solves this super good :)) I see no optimistic locking messages at all on all parallel threads in all my models
I read the documentation Transactions in Processes | docs.camunda.org and some other documentation also.
So what i am understanding of this async after is that save the process state until now??
So as per your statement if we are sure that our parallel states will not run into inconsistency then we can use async after on every last task of parallel gateway?
Please modify what ever you feel better for understanding.
You have to understand how commit of task works. It is not just marking current task is completed. Commit works from transaction point to transaction point, so few steps including joins can be processed in 1 transaction.
Marking async after before joint makes parallel gateway be out of transaction. Actually engine (job executor) yourself starts new transaction from this point before joint.