From 9f54a52de99e5169669975df2f96933276283e5d Mon Sep 17 00:00:00 2001 From: Ilan Steemers Date: Fri, 10 Jul 2015 11:30:54 +0200 Subject: [PATCH 1/5] edit link on the func column in the schedule admin --- django_q/admin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/django_q/admin.py b/django_q/admin.py index 6536291d..b306e618 100644 --- a/django_q/admin.py +++ b/django_q/admin.py @@ -74,6 +74,7 @@ class ScheduleAdmin(admin.ModelAdmin): list_filter = ('next_run', 'schedule_type') search_fields = ('func',) + list_display_links = ('id', 'func') admin.site.register(Schedule, ScheduleAdmin) From 977cf98ba0e01cf3fae092261b07961cb24410a1 Mon Sep 17 00:00:00 2001 From: Ilan Steemers Date: Fri, 10 Jul 2015 11:48:15 +0200 Subject: [PATCH 2/5] docs: made a note of succesful tasks not showing when the save_limit is set to -1 --- docs/admin.rst | 6 +++++- docs/install.rst | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/admin.rst b/docs/admin.rst index a2f5923b..9fc79649 100644 --- a/docs/admin.rst +++ b/docs/admin.rst @@ -16,7 +16,7 @@ Uses the :class:`Success` proxy model. .. tip:: - The maximum number of successful tasks can be set using the `save_limit` :ref:`configuration` option. + The maximum number of successful tasks can be set using the :ref:`save_limit` option. @@ -63,5 +63,9 @@ Success Indicates the success status of the last scheduled task, if any. +.. note:: + + if you have set the :ref:`save_limit` configuration option to not save successful tasks to the database, you will only see the failed results of your schedules. + Uses the :class:`Schedule` model diff --git a/docs/install.rst b/docs/install.rst index caf764bc..941685aa 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -77,6 +77,8 @@ compress Compresses task packages to Redis. Useful for large payloads, but can add overhead when used with many small packages. Defaults to ``False`` +.. _save_limit: + save_limit ~~~~~~~~~~ From fd168b320247a454e1317137541ff5d24da5f143 Mon Sep 17 00:00:00 2001 From: Ilan Steemers Date: Fri, 10 Jul 2015 12:05:00 +0200 Subject: [PATCH 3/5] Added `stopped` column in admin and sorting models on stopped field. --- django_q/admin.py | 2 ++ django_q/models.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/django_q/admin.py b/django_q/admin.py index b306e618..b2e06474 100644 --- a/django_q/admin.py +++ b/django_q/admin.py @@ -11,6 +11,7 @@ class TaskAdmin(admin.ModelAdmin): u'name', 'func', 'started', + 'stopped', 'time_taken' ) @@ -45,6 +46,7 @@ class FailAdmin(admin.ModelAdmin): 'name', 'func', 'started', + 'stopped', 'result' ) diff --git a/django_q/models.py b/django_q/models.py index 8a9e8b2c..98b3b62d 100644 --- a/django_q/models.py +++ b/django_q/models.py @@ -44,6 +44,7 @@ def __unicode__(self): class Meta: app_label = 'django_q' + ordering = ['-stopped'] @receiver(pre_save, sender=Task) @@ -78,6 +79,7 @@ class Meta: app_label = 'django_q' verbose_name = _('Successful task') verbose_name_plural = _('Successful tasks') + ordering = ['-stopped'] proxy = True @@ -94,6 +96,7 @@ class Meta: app_label = 'django_q' verbose_name = _('Failed task') verbose_name_plural = _('Failed tasks') + ordering = ['-stopped'] proxy = True From 90d30e14e8c70ce187d8e7ac1c8d53d4c5820efc Mon Sep 17 00:00:00 2001 From: Ilan Steemers Date: Fri, 10 Jul 2015 12:07:27 +0200 Subject: [PATCH 4/5] fixed regression of the save pruning due to introduction of uuid as primary key. --- django_q/cluster.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_q/cluster.py b/django_q/cluster.py index b3a1ee90..696ec359 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -389,7 +389,7 @@ def save_task(task): return # SAVE LIMIT > 0: Prune database, SAVE_LIMIT 0: No pruning if task['success'] and 0 < Conf.SAVE_LIMIT < Success.objects.count(): - Success.objects.first().delete() + Success.objects.last().delete() try: Task.objects.create(id=task['id'], From e5906286125418e4d9e0ca37b6e310cbdd27d9fd Mon Sep 17 00:00:00 2001 From: Ilan Steemers Date: Fri, 10 Jul 2015 12:14:57 +0200 Subject: [PATCH 5/5] linting some blank lines --- django_q/admin.py | 1 - django_q/apps.py | 1 + django_q/cluster.py | 5 ++--- django_q/conf.py | 2 ++ django_q/signing.py | 4 +++- django_q/tasks.py | 1 - 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/django_q/admin.py b/django_q/admin.py index b2e06474..7dacac58 100644 --- a/django_q/admin.py +++ b/django_q/admin.py @@ -1,5 +1,4 @@ from django.contrib import admin - from django.utils.translation import ugettext_lazy as _ from .tasks import async diff --git a/django_q/apps.py b/django_q/apps.py index 72705fde..54c09f1a 100644 --- a/django_q/apps.py +++ b/django_q/apps.py @@ -1,4 +1,5 @@ from django.apps import AppConfig + from .conf import Conf diff --git a/django_q/cluster.py b/django_q/cluster.py index 696ec359..2a3ec1c4 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -35,8 +35,6 @@ from django_q.monitor import Status, Stat - - class Cluster(object): def __init__(self, list_key=Conf.Q_LIST): try: @@ -450,7 +448,8 @@ def scheduler(list_key=Conf.Q_LIST): kwargs['list_key'] = list_key s.task = tasks.async(s.func, *args, **kwargs) if not s.task: - logger.error(_('{} failed to create a task from schedule {} [{}]').format(current_process().name, s.id), s.func) + logger.error(_('{} failed to create a task from schedule {} [{}]').format(current_process().name, s.id), + s.func) else: logger.info(_('{} created a task from schedule {} [{}]').format(current_process().name, s.id, s.func)) s.save() diff --git a/django_q/conf.py b/django_q/conf.py index b1956373..37e04bf7 100644 --- a/django_q/conf.py +++ b/django_q/conf.py @@ -64,6 +64,7 @@ class Conf(object): STOPPED = _('Stopped') STOPPING = _('Stopping') + # logger logger = logging.getLogger('django-q') @@ -90,5 +91,6 @@ def get_redis_client(): return django_redis.get_redis_connection(Conf.DJANGO_REDIS) return redis.StrictRedis(**Conf.REDIS) + # redis client redis_client = get_redis_client() diff --git a/django_q/signing.py b/django_q/signing.py index 963cc7ec..19e63419 100644 --- a/django_q/signing.py +++ b/django_q/signing.py @@ -4,10 +4,12 @@ import pickle from django.core import signing + from django_q.conf import Conf BadSignature = signing.BadSignature + class SignedPackage(object): """ Wraps Django's signing module with custom Pickle serializer @@ -41,4 +43,4 @@ def dumps(obj): @staticmethod def loads(data): - return pickle.loads(data) \ No newline at end of file + return pickle.loads(data) diff --git a/django_q/tasks.py b/django_q/tasks.py index 200669b9..9747fd13 100644 --- a/django_q/tasks.py +++ b/django_q/tasks.py @@ -107,4 +107,3 @@ def _sync(task_id, pack): result_queue.put('STOP') cluster.monitor(result_queue) return task_id -