camunda-community-hub / zeebe-client-node-js

Node.js client library for Zeebe Microservices Orchestration Engine
https://camunda-community-hub.github.io/zeebe-client-node-js/
Apache License 2.0
152 stars 38 forks source link

Add job.cancelWorkflow method #211

Closed jwulf closed 3 years ago

jwulf commented 3 years ago

Sometimes a worker makes a determination to cancel a workflow. With #210, the handler still needs to return a job action. A workaround is to do:

await zbc.cancelWorkflowInstance(
    job.workflowInstanceKey
)

return job.forward()

This is semantically incorrect, and a hack. The same can be said for job.complete() (which additionally would raise an error on the broker and on the client).

An alternative is to implement a job.cancelWorkflow() method that wraps this operation and can be returned like this:

return job.cancelWorkflow()