From 4ce44fe576abd1c3df3a79544b29b4fa0dc1f084 Mon Sep 17 00:00:00 2001 From: Ilan Steemers Date: Tue, 30 Jun 2015 16:57:21 +0200 Subject: [PATCH] Reworked kwargs for Python 2.7 compatibility --- django_q/core.py | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/django_q/core.py b/django_q/core.py index a51acd87..d5e20903 100644 --- a/django_q/core.py +++ b/django_q/core.py @@ -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) @@ -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 @@ -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, @@ -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() -