From baefee40095202ee845f5a401277d040738b98b6 Mon Sep 17 00:00:00 2001 From: Josh Wulf Date: Mon, 13 Jan 2025 14:08:27 +1300 Subject: [PATCH] chore: fix grpc interfaces for new method --- ...bCorrection.bpmn => Worker-JobResult.bpmn} | 0 .../Worker-CompleteWithResult.spec.ts | 6 +++-- src/zeebe/lib/ZBStreamWorker.ts | 23 ++++++++++++++++++- src/zeebe/zb/ZBWorker.ts | 6 +---- 4 files changed, 27 insertions(+), 8 deletions(-) rename src/__tests__/testdata/{Worker-JobCorrection.bpmn => Worker-JobResult.bpmn} (100%) diff --git a/src/__tests__/testdata/Worker-JobCorrection.bpmn b/src/__tests__/testdata/Worker-JobResult.bpmn similarity index 100% rename from src/__tests__/testdata/Worker-JobCorrection.bpmn rename to src/__tests__/testdata/Worker-JobResult.bpmn diff --git a/src/__tests__/zeebe/integration/Worker-CompleteWithResult.spec.ts b/src/__tests__/zeebe/integration/Worker-CompleteWithResult.spec.ts index 7dc0fb3c..643149f8 100644 --- a/src/__tests__/zeebe/integration/Worker-CompleteWithResult.spec.ts +++ b/src/__tests__/zeebe/integration/Worker-CompleteWithResult.spec.ts @@ -13,7 +13,7 @@ let bpmnProcessId1: string beforeAll(async () => { const res1 = await zbc.deployResource({ - processFilename: './src/__tests__/testdata/Worker-JobCorrection.bpmn', + processFilename: './src/__tests__/testdata/Worker-JobResult.bpmn', }) ;({ processDefinitionKey: processDefinitionKey1, @@ -48,7 +48,9 @@ test('Can complete a task with job corrections', (done) => { expect(job.processInstanceKey).toBe(wf?.processInstanceKey) const res1 = await job.completeWithJobResult({ variables: {}, - result: {}, + result: { + denied: true, + }, }) // @TODO: correction interface done(null) diff --git a/src/zeebe/lib/ZBStreamWorker.ts b/src/zeebe/lib/ZBStreamWorker.ts index 269d8625..f9d26b0e 100644 --- a/src/zeebe/lib/ZBStreamWorker.ts +++ b/src/zeebe/lib/ZBStreamWorker.ts @@ -15,7 +15,11 @@ import { ZBGrpc, ZBWorkerTaskHandler, } from './interfaces-1.0' -import { ActivatedJob, StreamActivatedJobsRequest } from './interfaces-grpc-1.0' +import { + ActivatedJob, + CompleteJobRequest, + StreamActivatedJobsRequest, +} from './interfaces-grpc-1.0' import { parseVariablesAndCustomHeadersToJSON } from '.' @@ -195,13 +199,30 @@ You should call only one job action method in the worker handler. This is a bug }) } + const correctJob = + (job: Job) => (req: Pick) => + this.completeJob( + job.key, + { + result: req.result, + variables: req.variables, + }, + taskType + ) + const fail = failJob(thisJob) const succeed = succeedJob(thisJob) + const completeWithResult = correctJob(thisJob) + return { cancelWorkflow: cancelWorkflow(thisJob), complete: errorMsgOnPriorMessageCall('job.complete', succeed), error: errorMsgOnPriorMessageCall('error', errorJob(thisJob)), fail: errorMsgOnPriorMessageCall('job.fail', fail), + completeWithJobResult: errorMsgOnPriorMessageCall( + 'job.completeWithJobResult', + completeWithResult + ), forward: errorMsgOnPriorMessageCall('job.forward', () => { return JOB_ACTION_ACKNOWLEDGEMENT }), diff --git a/src/zeebe/zb/ZBWorker.ts b/src/zeebe/zb/ZBWorker.ts index a8dbc566..0febeb17 100644 --- a/src/zeebe/zb/ZBWorker.ts +++ b/src/zeebe/zb/ZBWorker.ts @@ -49,11 +49,7 @@ export class ZBWorker< )( { ...job, - cancelWorkflow: workerCallback.cancelWorkflow, - complete: workerCallback.complete, - fail: workerCallback.fail, - error: workerCallback.error, - forward: workerCallback.forward, + ...workerCallback, }, this )