Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.
JustinAzoff edited this page Jan 7, 2011 · 10 revisions

Pyres is a Resque clone built in python. Each job in the queue corresponds to a python class that needs to define a perform method.

Let’s say I have a blog which needs to check comments for spam. When the comment is saved in the DB we create a job in the queue with comment data. Looks something like.

 class Comment(Model):
     name = Model.CharField()
     email = Model.EmailField()
     body = Model.TextField()
     spam = Model.BooleanField
     queue = "Spam"
#
     @staticmethod
     def perform(comment_id):
          // You ORM or SQL to get the comment data from the comment_id
          x = urllib.open("http://apikey.rest.akismet.com/1.1/comment-check?comment_author="+self.name.. so forth
          if x == "true":
               // save the comment spam field to true.
          else:
               // comment is fine.

You can convert your existing class to be compatible with Pyres. All you need to do is add a queue variable and define a perform method on the class.

To insert a job into the queue you need to do something like this:

from pyres import ResQ
r = Resq()
r.enqueue(Comment, 23)

This puts a job into the queue Spam. Now we need to fire off our workers. In the scripts folder there is an executable pyres_worker which is used to start a worker.
$ ./pyres_worker Spam

Just pass a comma seperated list of queues the worker should poll.

Clone this wiki locally