I have a process with some serviceTasks nodes. I use go client to provide job workers.
z.client.NewJobWorker().
JobType("serviceTask").
Handler(jobHandler).
Open()
func jobHandler(client worker.JobClient, job entities.Job) {
success := doSomeBusinessLogic()
if success {
// complete job
client.NewCompleteJobCommand().JobKey(job.Key).VariablesFromMap(toMerge).Send(context.Background())
} else {
// fail job
logAndNotifyError()
client.NewFailJobCommand().JobKey(job.GetKey()).Retries(job.Retries - 1).ErrorMessage(errorInfo).Send(ctx)
}
}
When I tried to cancel a failed process instance via Operate by click “cancel” button, I noticed that sometimes this jobHandler will be called again and the complete or fail command will report an error like
Command ‘CANCEL’ rejected with code ‘NOT_FOUND’: Expected to cancel a process instance with key ‘2251799813765247’, but no such process was found
This behavior is confusing I cannot determine that wether jobHandler is called by a normal activated job or a cancel operation so that I can ignore business logic code running to avoid unexpected duplicated execution.
So is there a way to find out
- how can I avoid cancel command activate my jobHandler again?
- or if I can know this run is triggered by a cancel command?
Environment(I also met this problem before in 1.x):
- Self-hosted zeebe 8.0.0
- Self-hosted operate 8.0.0
thanks for your suggestions.