OptimalBits / bull

Premium Queue package for handling distributed jobs and messages in NodeJS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get worker by job id?

vickyRathee opened this issue · comments

Is there any way to find the worker running a job?

I can use getWorkers() to get all the workers, which return the id, name etc.

[{"id":"15","addr":"127.0.0.1:37526","fd":"20","name":"myQueue","age":"852","idle":"2","flags":"b","db":"0","sub":"0","psub":"0","multi":"-1","qbuf":"0","qbuf-free":"0","obl":"0","oll":"0","omem":"0","events":"r","cmd":"brpoplpush"},

But I can't find a way to get the worker details by jobId. As I want to treekill the worker to reboot when a job is stalled.

  @OnGlobalQueueStalled()
  async onQueueStalled(jobId: number) {
    const wokers = await this.queue.getWorkers(); 
    // Find the worker running this job and use `addr` to
    // Kill and reboot this worker
  }

Bull version

4.10.4

Additional information

No, atm there is no way to easily get the job that is processing a given job. Every worker has a special token used to lock the jobs when processing them, so it should be possible to map them in theory.

@manast thanks for the comment, here is my workaround if anyone else have similar scenario.

// Set pid on processor, before starting the execution.
await job.update({ ...job.data, pid: process.pid });

Now we can get he pid from data when needed.

const { pid } = job.data;