Resque:每个队列一名工人 [英] Resque: one worker per queue

查看:127
本文介绍了Resque:每个队列一名工人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个Rails 3.0项目,其中包含Ruby 1.9.2和Resque.

I currently have a Rails 3.0 project, with Ruby 1.9.2 and Resque.

我的应用程序具有多个工作程序类和多个队列,它们是动态创建的(在运行时期间).另外,有多个启动的工人可以在任何队列上自由工作,因为在开始时没有任何现有的队列,并且无法预测它们:

My application has multiple worker classes and multiple queues, that are dynamically created (during runtime). Also, there are multiple workers started that are free to work on any queues, because at start time there isn't any existing queues, and they cannot be predicted:

$ COUNT=3 QUEUE=* rake resque:workers

将基于project的ID创建的创建队列:

Queues a created based on the project's id:

@queue = "project_#{project.id}".to_sym

对于给定的队列,他们的作业必须按顺序处理,并且一次处理一次.我的问题是,通过拥有多个工作人员,可以并行处理多个作业.

For a given queue, their jobs have to processed in order and one at a time. My problem is that, by having multiple workers, multiple jobs are processed in parallel.

是否可以将每个队列的最大工作程序数设置为1?有没有办法在处理作业时锁定队列?

Is there a way to set the maximum number of workers per queue (to 1)? Is there a way to lock a queue while a job is processing?

谢谢!

推荐答案

我终于找到了一个非常简单的解决方案,使用resque-retry和存储在redis中的锁(我是为用户这样做的,只为项目这样做): https://stackoverflow.com/a/10933666/745266

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

这篇关于Resque:每个队列一名工人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆