Permalink
Browse files

Added possibility to get current retry as parameter

  • Loading branch information...
1 parent 31756ea commit 29b2a8f23c7df6bb4fe8efb68a5af43dc0acf091 @lfriedrich lfriedrich committed Apr 18, 2012
Showing with 7 additions and 5 deletions.
  1. +5 −3 huey/decorators.py
  2. +2 −2 huey/djhuey/decorators.py
View
@@ -7,9 +7,11 @@
from huey.utils import local_to_utc
-def create_command(command_class, func, **kwargs):
+def create_command(command_class, func, retries_as_argument=False, **kwargs):
def execute(self):
args, kwargs = self.data or ((), {})
+ if retries_as_argument:
+ kwargs['retries'] = self.retries
return func(*args, **kwargs)
attrs = {
@@ -27,7 +29,7 @@ def execute(self):
return klass
-def queue_command(invoker, retries=0, retry_delay=0):
+def queue_command(invoker, retries=0, retry_delay=0, retries_as_argument=False):
def decorator(func):
"""
Decorator to execute a function out-of-band via the consumer. Usage::
@@ -36,7 +38,7 @@ def decorator(func):
def send_email(user, message):
... this code executed when dequeued by the consumer ...
"""
- klass = create_command(QueueCommand, func)
+ klass = create_command(QueueCommand, func, retries_as_argument)
def schedule(args=None, kwargs=None, eta=None, convert_utc=True):
if convert_utc and eta:
@@ -4,12 +4,12 @@
from huey.djhuey import invoker
-def queue_command(retries=0, retry_delay=0):
+def queue_command(retries=0, retry_delay=0, retries_as_argument=False):
if type(retries) == types.FunctionType:
return _queue_command(invoker)(retries)
def inner(fn):
- return _queue_command(invoker, retries, retry_delay)(fn)
+ return _queue_command(invoker, retries, retry_delay, retries_as_argument)(fn)
return inner
def periodic_command(crontab):

0 comments on commit 29b2a8f

Please sign in to comment.