Implementing Resque
Chiel Wester wo 24 feb 10
A while ago i posted an article with the announcement that Github’s new background worker library ‘Resque’ had made its way to the public community.
Now that i’m working with resque myself for some jobs, it’s time to give you a little summary of the way resque works and how you should implement it.
Background jobs
With resque, every Ruby class with a perform method can be used as a background job. So all you have to do to implement a background job is creating a class and add the self.perform method!
Remember that you need to set the queue name of the queue the job should be put in:
class Archive @queue = :queue_name ... def self.perform(args = {}) end end
Startup Redis
Before you can add any jobs to the queue, you need to start the queue manager for resque: redis. After installing redis, you can simply start is with the command ‘redis-server’.
Queueing jobs
To add a new job to the queue you simply need to make a call to Resque.enqueue with the class name of the job you want to enqueue and some additional arguments:
Resque.enqueue(Archive, arguments)
Keep in mind that it must be possible to marshal the additional arguments to json format! (This is because the queues of Resque are saved in json format in the redis server)
Now let’s do some work!
After adding jobs to the queue, all there’s left to do is start a worker to work through the queue and perform all the jobs you have put in the queues. This can be done with a simple rake task. First put the following line in the Rakefile of your application:
require 'resque/tasks'
After that, run the following command:
QUEUE=* rake environment resque:work
Workers for all existing queues will start and run all enqueued jobs!
Resque-web
With resque-web you can watch all running processes in resque. resque-web is a simple web interface that shows you information about queues, running workers and failed jobs. Just run ‘resque-web’ and open the url in your browser!

Gepost in hor | 0 reacties
Welkom op Holland On Rails
Het startpunt voor Ruby On Rails in Nederland. Vind de laatste technieken, meningen en nieuwtjes.Recente Jobs
Gezocht: Ruby On Rails ontwikkelaar (junior of senior)
Eet, drink en droom jij over Ruby On Rails? Wil jij het liefste dag en nacht bezig zijn met jehobby; super coole webapplicaties ontwikkelen in Ruby On Rails?
Dan willen wij jou graag een podium bieden om je Ruby skills te vertonen aan onze nationale en internationale klanten!
@ Internetbureau Holder, Obdam
Bekijk alle jobs »»
Gereedschapskist
Onmisbare tools vooriedere developer!
- Ruby On Rails
Framework voor de web 2.0 developer. Eindelijk vooruitgang! - TextMate
Editor for true pro's
Typ, tab, top :-)
Nee, niet voor Win. - Made On A Mac
En nou is het over met die saaie grijze Windows bak van je!
Auteurs op deze site
Chris Obdam
'Less is more' evangelist, past dit ook dagelijks toe op zijn tandenborstel.Chiel Wester
Snelheidswonder op Ruby wielen. Leuk om mee te pair-programmen ;-)
Plaats je reactie