Job worker invoking another job worker

I have a service task that invoke JobWorker A. In JobWorker A, can I invoke JobWorker B? If so, how can I achieve this? What is the API to invoke another job worker? I tried:

ActivateJobsResponse response = client.newActivateJobsCommand()
                .jobType("dummyWorker")
                .maxJobsToActivate(1)
                .send()
                .join();

    //Then
    ActivatedJob activatedJob = response.getJobs().get(0);

Obviously this doesnt work. zero jobs returned, resulting in index out of bound.

Hi @khew - job workers are invoked by the process itself, not an API call. I think you have two options:

  1. you can explicitly model the next job worker as a service task in your process, with a gateway before if needed. This is the route I would recommend because it is explicit about what is being invoked, when it is being invoked, and is therefore a more accurate reflection of your actual process than “hiding” the second job worker inside the first task.
  2. refactor your job worker to have it’s logic contained in it’s own class and methods, and call that class/method from both job workers.
1 Like

Thank you @nathan.loding for your answer. Ok got it, we cannot invoke job worker from another job worker.

I’m curious then, what does client.newActivateJobsCommand() API does?

@khew - in short, it’s the command a job worker uses to invoke a queued job. The endpoint is documented here, and you can read about job worker activation here:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.