mirror of
https://github.com/django-q2/django-q2.git
synced 2026-09-21 07:28:12 +08:00
+3
-1
@@ -1,5 +1,4 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from .tasks import async
|
||||
@@ -11,6 +10,7 @@ class TaskAdmin(admin.ModelAdmin):
|
||||
u'name',
|
||||
'func',
|
||||
'started',
|
||||
'stopped',
|
||||
'time_taken'
|
||||
)
|
||||
|
||||
@@ -45,6 +45,7 @@ class FailAdmin(admin.ModelAdmin):
|
||||
'name',
|
||||
'func',
|
||||
'started',
|
||||
'stopped',
|
||||
'result'
|
||||
)
|
||||
|
||||
@@ -74,6 +75,7 @@ class ScheduleAdmin(admin.ModelAdmin):
|
||||
|
||||
list_filter = ('next_run', 'schedule_type')
|
||||
search_fields = ('func',)
|
||||
list_display_links = ('id', 'func')
|
||||
|
||||
|
||||
admin.site.register(Schedule, ScheduleAdmin)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
from .conf import Conf
|
||||
|
||||
|
||||
|
||||
+3
-4
@@ -35,8 +35,6 @@ from django_q.models import Task, Success, Schedule
|
||||
from django_q.monitor import Status, Stat
|
||||
|
||||
|
||||
|
||||
|
||||
class Cluster(object):
|
||||
def __init__(self, list_key=Conf.Q_LIST):
|
||||
try:
|
||||
@@ -389,7 +387,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'],
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -44,6 +44,7 @@ class Task(models.Model):
|
||||
|
||||
class Meta:
|
||||
app_label = 'django_q'
|
||||
ordering = ['-stopped']
|
||||
|
||||
|
||||
@receiver(pre_save, sender=Task)
|
||||
@@ -78,6 +79,7 @@ class Success(Task):
|
||||
app_label = 'django_q'
|
||||
verbose_name = _('Successful task')
|
||||
verbose_name_plural = _('Successful tasks')
|
||||
ordering = ['-stopped']
|
||||
proxy = True
|
||||
|
||||
|
||||
@@ -94,6 +96,7 @@ class Failure(Task):
|
||||
app_label = 'django_q'
|
||||
verbose_name = _('Failed task')
|
||||
verbose_name_plural = _('Failed tasks')
|
||||
ordering = ['-stopped']
|
||||
proxy = True
|
||||
|
||||
|
||||
|
||||
+3
-1
@@ -4,10 +4,12 @@ except ImportError:
|
||||
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 @@ class PickleSerializer(object):
|
||||
|
||||
@staticmethod
|
||||
def loads(data):
|
||||
return pickle.loads(data)
|
||||
return pickle.loads(data)
|
||||
|
||||
@@ -107,4 +107,3 @@ def _sync(task_id, pack):
|
||||
result_queue.put('STOP')
|
||||
cluster.monitor(result_queue)
|
||||
return task_id
|
||||
|
||||
|
||||
+5
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
~~~~~~~~~~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user