Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resque: one worker per queue

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

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.

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?

Thanks!

like image 613
Henrique Zambon Avatar asked Feb 13 '12 19:02

Henrique Zambon


2 Answers

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

like image 69
lacco Avatar answered Sep 24 '22 20:09

lacco


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

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

like image 44
Nick Avatar answered Sep 22 '22 20:09

Nick