zeebe-node
Version:
The Node.js client library for the Zeebe Workflow Automation Engine.
73 lines • 2.81 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZBWorker = void 0;
const ZBWorkerBase_1 = require("../lib/ZBWorkerBase");
class ZBWorker extends ZBWorkerBase_1.ZBWorkerBase {
constructor(config) {
super(config);
}
handleJobs(jobs) {
// Call task handler for each new job
jobs.forEach(async (job) => this.handleJob(job));
}
async handleJob(job) {
try {
/**
* complete.success(variables?: object) and complete.failure(errorMessage: string, retries?: number)
*
* To halt execution of the business process and raise an incident in Operate, call
* complete.failure(errorMessage, 0)
*/
const workerCallback = this.makeCompleteHandlers(job);
await this.taskHandler({
...job,
cancelWorkflow: workerCallback.cancelWorkflow,
complete: workerCallback.complete,
fail: workerCallback.fail,
error: workerCallback.error,
forward: workerCallback.forward,
}, this);
}
catch (e) {
this.logger.logError(`Caught an unhandled exception in a task handler for process instance ${job.processInstanceKey}:`);
this.logger.logDebug(job);
this.logger.logError(e.message);
if (this.cancelWorkflowOnException) {
const { processInstanceKey } = job;
this.logger.logDebug(`Cancelling process instance ${processInstanceKey}`);
try {
await this.zbClient.cancelProcessInstance(processInstanceKey);
}
finally {
this.drainOne();
}
}
else {
this.logger.logInfo(`Failing job ${job.key}`);
const retries = job.retries - 1;
try {
this.zbClient.failJob({
errorMessage: `Unhandled exception in task handler ${e}`,
jobKey: job.key,
retries,
retryBackOff: 0,
});
}
catch (e) {
this.logger.logDebug(e);
}
finally {
this.drainOne();
if (retries > 0) {
this.logger.logDebug(`The Zeebe engine will handle the retry. Retries left: ${retries}`);
}
else {
this.logger.logDebug('No retries left for this task');
}
}
}
}
}
}
exports.ZBWorker = ZBWorker;
//# sourceMappingURL=ZBWorker.js.map
;