How to terminate the process programatically?

I’m using nestjs-zeebe, I have a problem that when the result is failed it doesn’t terminate the process right away but instead, it wait couple seconds and get this kind of error.

DEADLINE_EXCEEDED: Time out between gateway and broker: Request ProtocolRequest{id=4464, subject=command-api-1, sender=0.0.0.0:26502, payload=byte[]{length=256, hash=-1121886258}} to 0.0.0.0:26501 timed out in PT15S

@ZeebeWorker('cognito:user:create')
  async createCognitoUser(
    @Payload() job: ZeebeJob<CreateUserDto>,
  ): Promise<void> {
    try {
      const user = await this.cognitoService.create(job.variables);
      await job.complete({ userId: user?.Username });
    } catch (error) {
      this.logger.error(error);
      if (error instanceof EmailAddressAlreadyRegistered) {
        await job.complete({ error: { message: error.message } });
      }
    }
  }

I tried all possible functions in the job and some retry and requestTimeout config on my broker but no luck. All I want is once I got the error result, just terminate the process return me the result

I’m not versed in NestJS nor all the broker pieces…
But why use job.complete for an error rather than job.error ?

Sorry, but it was originally job.error. I don’t have exact idea what causing this issue. When it succeed, the process is normal. I get the response right after. Only problem is when it fails. I’m not sure if its because of my model

After failed to create user, it must be stop already?

The error message indicates an issue communicating between the Gateway and Broker.

What version of Zeebe are you using?
The error should take approximately 15s… If it’s taking a lot less than that, it’s possible it’s from somewhere else in your process.

I’m using the camunda-zeebe-8.3.0-alpha1. Yes, its like about 15 sec but it shouldn’t wait anymore because I have the result. And it doesn’t catch on Nest JS I got internet server error 500. Maybe its from nest js not in zeebe

Not likely.
The message indicates that the communication got to the gateway, but couldn’t get to the broker.
If you run through your process using tasklist or postman to move the token along, does it work better?

Anyways, I already found the issue. I need to catch the error so I added an error boundaries. It works it terminates the process now. But the problem is the const result = await this.zbc.createProcessInstanceWithResult returns empty no matter what, unless I throw an error inside the worker but its not ideal. I have to use the BpmnError but I don’t know how to pass at least the errorcode or the message, it seems no avaible way? They got a really bad error handling feature tbh.

So basically, to get the error response back you need to set up new task and perform another job.complete?

Your worker shouldn’t be calling CreateProcessInstanceWithResult. If your worker exists to create another process instance, then you should simply call the CreateProcess, and then poll to see when it’s done. But really, if that’s the case, why aren’t you using “Call Activity”

CreateProcessInstanceWithResult would be something an external program would call to start the overall process. It will run until it either hits an async or until the Gateway times out, which would then return an empty response.

This isn’t exact (nor accurate), but it’s something along the lines of this…

1 Like