diff --git a/src/__tests__/zeebe/integration/Worker-JobCorrection.spec.ts b/src/__tests__/zeebe/integration/Worker-CompleteWithResult.spec.ts similarity index 91% rename from src/__tests__/zeebe/integration/Worker-JobCorrection.spec.ts rename to src/__tests__/zeebe/integration/Worker-CompleteWithResult.spec.ts index bda8976c..7dc0fb3c 100644 --- a/src/__tests__/zeebe/integration/Worker-JobCorrection.spec.ts +++ b/src/__tests__/zeebe/integration/Worker-CompleteWithResult.spec.ts @@ -46,9 +46,11 @@ test('Can complete a task with job corrections', (done) => { taskType: 'job-correction', taskHandler: async (job) => { expect(job.processInstanceKey).toBe(wf?.processInstanceKey) - const res1 = await job.complete({ - // @TODO: correction interface + const res1 = await job.completeWithJobResult({ + variables: {}, + result: {}, }) + // @TODO: correction interface done(null) return res1 }, diff --git a/src/zeebe/lib/ZBWorkerBase.ts b/src/zeebe/lib/ZBWorkerBase.ts index 23c5ff67..cf532053 100644 --- a/src/zeebe/lib/ZBWorkerBase.ts +++ b/src/zeebe/lib/ZBWorkerBase.ts @@ -20,6 +20,8 @@ import * as ZB from './interfaces-1.0' import { ActivateJobsRequest, ActivateJobsResponse, + CompleteJobRequest, + JobResult, } from './interfaces-grpc-1.0' import { ZBClientOptions } from './interfaces-published-contract' @@ -340,6 +342,14 @@ You should call only one job action method in the worker handler. This is a bug (completedVariables?: T) => this.completeJob(job.key, completedVariables ?? {}) + const correctJob = + (job: ZB.Job) => + (req: Pick) => + this.completeJob(job.key, { + result: req.result, + variables: req.variables, + }) + const errorJob = (job: ZB.Job) => (e: string | ZB.ErrorJobWithVariables, errorMessage: string = '') => { @@ -362,9 +372,14 @@ You should call only one job action method in the worker handler. This is a bug const fail = failJob(thisJob) const succeed = succeedJob(thisJob) + const completeWithResult = correctJob(thisJob) return { cancelWorkflow: cancelWorkflow(thisJob), complete: errorMsgOnPriorMessageCall('job.complete', succeed), + completeWithJobResult: errorMsgOnPriorMessageCall( + 'job.completeWithJobResult', + completeWithResult + ), error: errorMsgOnPriorMessageCall('error', errorJob(thisJob)), fail: errorMsgOnPriorMessageCall('job.fail', fail), forward: errorMsgOnPriorMessageCall('job.forward', () => { @@ -402,11 +417,16 @@ You should call only one job action method in the worker handler. This is a bug }) } - private completeJob(jobKey: string, completedVariables = {}) { + private completeJob( + jobKey: string, + completedVariables = {}, + result: JobResult = {} + ) { return this.zbClient .completeJob({ jobKey, variables: completedVariables, + result, }) .then((res) => { this.logger.logDebug(`Completed job ${jobKey} for ${this.taskType}`) diff --git a/src/zeebe/lib/interfaces-1.0.ts b/src/zeebe/lib/interfaces-1.0.ts index 979bd692..e997b667 100644 --- a/src/zeebe/lib/interfaces-1.0.ts +++ b/src/zeebe/lib/interfaces-1.0.ts @@ -178,6 +178,12 @@ export interface JobCompletionInterface { complete: ( updatedVariables?: WorkerOutputVariables ) => Promise + /** + * Complete the job with success, and a job result that may contain corrections. Since Camunda 8.7. + */ + completeWithJobResult: ( + req: Pick + ) => Promise /** * Fail the job with an informative message as to the cause. Optionally, pass in a * value remaining retries. If no value is passed for retries then the current retry