Skip to content
This repository was archived by the owner on Apr 8, 2024. It is now read-only.

Commit b9f500c

Browse files
authored
Merge pull request #131 from jwulf/129-complete-forwarded
Fixes #129 - add complete.forwarded
2 parents 6a6819d + 0772c05 commit b9f500c

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,20 +331,26 @@ zbc.createWorker('test-worker', 'console-log', maybeFaultyHandler, {
331331
})
332332
```
333333
334-
### Completing tasks with success, failure, or error
334+
### Completing tasks with success, failure, error, or forwarded
335335
336336
To complete a task, the task worker handler function receives a `complete` parameter. The complete object has `success`, `failure`, and `error` methods.
337337
338338
Call `complete.success()` passing in a optional plain old JavaScript object (POJO) - a key:value map. These are variable:value pairs that will be used to update the workflow state in the broker. They will be merged with existing values. You can set an existing key to `null` or `undefined`, but there is no way to delete a key.
339339
340340
Call `complete.failure()` to fail the task. You must pass in a string message describing the failure. The client library decrements the retry count, and the broker handles the retry logic. If the failure is a hard failure and should cause an incident to be raised in Operate, then pass in `0` for the optional second parameter, `retries`:
341341
342-
Call `complete.error()` to trigger a BPMN error throw event. You must pass in a string error code for the error code, and you can pass an optional error message as the second parameter. If no BPMN error catch event exists for the error code, an incident will be raised.
343-
344342
```javascript
345343
complete.failure('This is a critical failure and will raise an incident', 0)
346344
```
347345
346+
Call `complete.error()` to trigger a BPMN error throw event. You must pass in a string error code for the error code, and you can pass an optional error message as the second parameter. If no BPMN error catch event exists for the error code, an incident will be raised.
347+
348+
Call `complete.forwarded()` to release worker capacity to handle another job, without completing the job in any way with the Zeebe broker. This method supports the _decoupled job completion_ pattern. In this pattern, the worker forwards the job to another system - a lambda or a RabbitMQ queue. Some other process is ultimately responsible for completing the job.
349+
350+
## Completing jobs in the decoupled job completion pattern
351+
352+
You can use the ZBClient methods `completeJob()`, `failJob()`, and `throwError()` in the decoupled pattern to complete jobs that were activated by another process. In contrast to the worker `complete` methods, the ZBClient methods require a specific job key, so you must pass the job key with the job data when forwarding the job from the worker that activates it to a remote system.
353+
348354
### Long polling
349355
350356
With Zeebe 0.21 onward, long polling is supported for clients, and is used by default. Rather than polling continuously for work and getting nothing back, a client can poll once and leave the request open until work appears. This reduces network traffic and CPU utilization in the server. Every JobActivation Request is appended to the event log, so continuous polling can significantly impact broker performance, especially when an exporter is loaded (see [here](https://github.com/creditsenseau/zeebe-client-node-js/issues/64#issuecomment-520233275)).

src/lib/interfaces.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ export interface CompleteFn<WorkerOutputVariables> {
2727
* count is decremented. Pass in `0`for retries to raise an incident in Operate.
2828
*/
2929
failure: (errorMessage: string, retries?: number) => void
30+
/**
31+
* Mark this job as forwarded to another system for completion. No action is taken by the broker.
32+
* This method releases worker capacity to handle another job.
33+
*/
34+
forwarded: () => void
3035
/**
3136
*
3237
* Report a business error (i.e. non-technical) that occurs while processing a job.

src/zb/ZBClient.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ export class ZBClient extends EventEmitter {
241241
): Promise<void> {
242242
const withStringifiedVariables = stringifyVariables(completeJobRequest)
243243
this.logger.debug(withStringifiedVariables)
244-
return this.gRPCClient.completeJobSync(withStringifiedVariables)
244+
return this.executeOperation('completeJob', () =>
245+
this.gRPCClient.completeJobSync(withStringifiedVariables)
246+
)
245247
}
246248

247249
// tslint:disable: no-object-literal-type-assertion

src/zb/ZBWorker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ export class ZBWorker<
310310
* complete.success(variables?: object) and complete.failure(errorMessage: string, retries?: number)
311311
*
312312
* To halt execution of the business process and raise an incident in Operate, call
313-
* complete(errorMessage, 0)
313+
* complete.failure(errorMessage, 0)
314314
*/
315315

316316
const workerCallback = {
@@ -345,6 +345,7 @@ export class ZBWorker<
345345
this.drainOne()
346346
}
347347
},
348+
forwarded: () => this.drainOne(),
348349
success: async (completedVariables = {}) => {
349350
let res
350351
try {

0 commit comments

Comments
 (0)