Best Practices for Handling Long-Running Service Tasks in Node.js

Hi
I’m looking for the best pattern to handle service tasks that may run for a long time. I know that when we’re using a worker (like the createWorker function or one level higher the job streaming), under the hood, the SDK activates and locks that job for that particular worker so the worker can complete or fail it if required.

what if the service task requires a long period to complete? we can’t just leave the worker hanging until it is complete

for example we might call API to another service that does some sort of heavy computation that may take an hour, or we come across a situation where a service tasks requires a day to complete.

I’m not sure extending the timeout would be an appropriate solution, please correct me if I’m wrong.

this whole situation here is somehow ambiguous for me so any advice would be highly appreciated.

thank you in advance.

zbGrpcClient.streamJobs({
  type: "the type defined in the modeler",
  worker: "some string",
  tenantIds: [],
  pollMaxJobsToActivate: 5, //should be a number
  timeout: 30_000, // **this is related to the question**
  taskHandler: async (job) {
    // business logic code 
    // there may be API calls to other services here

    return job.complete(); //this must be called and be returned
  }
});

For long-running service tasks, the recommended approach is to implement a heartbeat pattern by periodically extending the job timeout using the UpdateJobTimeout gRPC command, rather than setting extremely long static timeouts. I found the following relevant resources:

Does this help? If not, can anyone from the community jump in? :waving_hand:


:light_bulb: Hints: Use the Ask AI feature in Camunda’s documentation to chat with AI and get fast help. Report bugs and features in Camuda’s GitHub issue tracker. Trust the process. :robot: