开发者

Detect which worker returned a TTR-expired job to the queue?

开发者 https://www.devze.com 2023-04-04 17:24 出处:网络
I have multiple workers processing requests in a beanstalkd queue using beanstalk-client-ruby. For testing purposes, the workers randomly dive into an infinite loop after picking up a job from the qu

I have multiple workers processing requests in a beanstalkd queue using beanstalk-client-ruby.

For testing purposes, the workers randomly dive into an infinite loop after picking up a job from the queue.

Beanstalk notices that a job has been reserved for too long and returns it to the queue for other workers to proc开发者_如何学Pythoness.

How could I detect that this has happened, so that I can kill the malfunctioning worker?

Looks like I can get detect that a timeout has happened :

> job.timeouts
 => 0
> sleep 10
 => nil
> job.timeouts
 => 1

Now how can I something like:

> job=queue.reserve
 => 189
> job.MAGICAL_INFO_STORE[:previous_worker_pid] = $$
 => extraordinary magic happened
> sleep 10
 => nil
> job=queue.reserve
 => 189
> job.timeouts
 => 1
> kill_the_sucker(job.MAGICAL_INFO_STORE[:previous_worker_pid])
 => nil


Found a working solution myself:

  1. Reserve a job
  2. Setup a new tube with the job_id
  3. Push a job with your PID in the body to the new tube
  4. When a job with timeouts > 0 is found, pop the PID-task from the job_id queue.
  5. Kill the worker
0

精彩评论

暂无评论...
验证码 换一张
取 消