Skip to content

Commit

Permalink
document class tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Aug 3, 2013
1 parent 7b1ca5d commit eac4346
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
56 changes: 56 additions & 0 deletions docs/classtasks.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Class Tasks
-----------

"Class Tasks" are tasks defined as a class method.
They provide very basic primitive method of serialization and deserialization
when sending and receiving tasks.

It is better to explain with an example:

.. code-block:: python
from kuyruk import Kuyruk
kuyruk = Kuyruk()
# This is your base database model
class Base(object):
# This is the primary key
id = Column(Integer)
# You need to override this function to return
# the instance by fetching from database
@classmethod
def get(cls, id):
# Something like this:
return session.query(cls).get(id)
class Mp4(Base):
# some fields...
user_id = Column(Integer)
file_id = Column(Integer)
created_at = Column(Datetime)
@kuyruk.task
def convert(self, resolution='480p'):
print "Converting MP4(%s)..." % resolution
# Do the actual conversion here
# Lets create an Mp4 instance
mp4 = Mp4(user_id=6, file_id=1234)
# The instance must be persisted to database befor sending to queue
session.add(mp4)
session.commit()
print mp4.id
>>> 34
# Calling task method will send a message to the queue
mp4.convert(resolution='720p')
When you run the worker it will try to fetch the insance by
calling ``Mp4.get(34)``. Then it will call ``mp4.convert(resolution='720p')``.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ User's Guide
commands
signals
events
classtasks
extending


Expand Down

0 comments on commit eac4346

Please sign in to comment.