Skip to content

Commit

Permalink
Reworked kwargs for Python 2.7 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Koed00 committed Jun 30, 2015
1 parent 4096b35 commit 4ce44fe
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions django_q/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,24 +385,11 @@ def async(func, *args, **kwargs):
"""
Sends a task to the cluster
"""
# Check for hook
if 'hook' in kwargs:
hook = kwargs['hook']
del kwargs['hook']
else:
hook = None
# Check for list_key override
if 'list_key' in kwargs:
list_key = kwargs['list_key']
del kwargs['list_key']
else:
list_key = Conf.Q_LIST
# Check for redis connection override
if 'redis' in kwargs:
r = kwargs['redis']
del kwargs['redis']
else:
r = redis_client

hook = kwargs.pop('hook', None)
list_key = kwargs.pop('list_key', Conf.Q_LIST)
r = kwargs.pop('redis', redis_client)

task = {'name': uuid()[0], 'func': func, 'hook': hook, 'args': args, 'kwargs': kwargs, 'started': timezone.now()}
pack = SignedPackage.dumps(task)
r.rpush(list_key, pack)
Expand Down Expand Up @@ -551,7 +538,7 @@ def __getstate__(self):
return state


def schedule(func, *args, hook=None, schedule_type=Schedule.ONCE, repeats=-1, next_run=timezone.now(), **kwargs):
def schedule(func, *args, **kwargs):
"""
:param func: function to schedule
:param args: function arguments
Expand All @@ -565,6 +552,11 @@ def schedule(func, *args, hook=None, schedule_type=Schedule.ONCE, repeats=-1, ne
:rtype: Schedule
"""

hook = kwargs.pop('hook', None)
schedule_type = kwargs.pop('schedule_type', Schedule.ONCE)
repeats = kwargs.pop('repeats', -1)
next_run = kwargs.pop('next_run', timezone.now())

return Schedule.objects.create(func=func,
hook=hook,
args=args,
Expand Down Expand Up @@ -623,4 +615,3 @@ def scheduler(list_key=Conf.Q_LIST):
else:
logger.info('{} created [{}] from schedule {}'.format(current_process().name, s.task, s.id))
s.save()

0 comments on commit 4ce44fe

Please sign in to comment.