Resque: one worker per queue

不打扰是莪最后的温柔 提交于 2019-12-03 13:17:54
lacco

I finally came to a quite simple solution using resque-retry and locks stored in redis (I am doing this for users, just do it for projects): https://stackoverflow.com/a/10933666/745266

The first solution I thought of would be to check if there is any worker working in a given queue when there's another worker polling that same queue. This could be done by reimplementing Resque::Job.reserve(queue):

module Resque
  class Job

    def self.reserve(queue)

      Resque::Worker.working.each do |worker|
        # if already working in the same queue
        if worker.job['queue'] == queue
          return
        end
      end

      return unless payload = Resque.pop(queue)
      new(queue, payload)
    end

  end
end

A possible issue would be the race condition. Thoughts?

Resque-pool can help you specify number of workers per queue.

https://github.com/nevans/resque-pool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!