Skip to content

Commit

Permalink
chore: fix grpc interfaces for new method
Browse files Browse the repository at this point in the history
  • Loading branch information
jwulf committed Jan 13, 2025
1 parent e51853b commit 46b17c2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 22 additions & 1 deletion src/zeebe/lib/ZBStreamWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 '.'

Expand Down Expand Up @@ -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<CompleteJobRequest, 'result' | 'variables'>) =>
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
}),
Expand Down
6 changes: 1 addition & 5 deletions src/zeebe/zb/ZBWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit 46b17c2

Please sign in to comment.