<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Implementing Resque</title>
    <link>http://hollandonrails.nl/articles/478-Implementing-Resque</link>
    <description>A &quot;while ago i posted an article&quot;:http://hollandonrails.nl/articles/429-Resque-another-background-library with the announcement that Github's new background worker library &quot;'Resque'&quot;:http://github.com/defunkt/resque had made its way &quot;to the public community&quot;:http://github.com/blog/542-introducing-resque.

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:

&lt;code&gt;
class Archive
  @queue = :queue_name
  ...
  
  def self.perform(args = {})

  end
end
&lt;/code&gt;

*Startup Redis*
Before you can add any jobs to the queue, you need to start the queue manager for resque: &quot;redis&quot;:http://code.google.com/p/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:

&lt;code&gt;
Resque.enqueue(Archive, arguments)
&lt;/code&gt;

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:

&lt;code&gt;
require 'resque/tasks'
&lt;/code&gt;

After that, run the following command:

&lt;code&gt;
QUEUE=* rake environment resque:work
&lt;/code&gt;

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!

!http://hollandonrails.nl/system/Resque.jpg!</description>
  </channel>
</rss>
