Merge pull request #220 from abompard/signals

Adds basic signals
This commit is contained in:
Ilan Steemers
2017-04-05 16:28:05 +03:00
committed by GitHub
5 changed files with 57 additions and 2 deletions
+5 -1
View File
@@ -34,6 +34,7 @@ from django_q.conf import Conf, logger, psutil, get_ppid, rollbar
from django_q.models import Task, Success, Schedule
from django_q.status import Stat, Status
from django_q.brokers import get_broker
from django_q.signals import pre_execute
class Cluster(object):
@@ -373,8 +374,11 @@ def worker(task_queue, result_queue, timer, timeout=Conf.TIMEOUT):
# We're still going
if not result:
db.close_old_connections()
timer_value = task['kwargs'].pop('timeout', timeout or 0)
# signal execution
pre_execute.send(sender="django_q", func=f, task=task)
# execute the payload
timer.value = task['kwargs'].pop('timeout', timeout or 0) # Busy
timer.value = timer_value # Busy
try:
res = f(*task['args'], **task['kwargs'])
result = (res, True)
+5 -1
View File
@@ -1,7 +1,7 @@
import importlib
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.dispatch import receiver, Signal
from django.utils.translation import ugettext_lazy as _
from django_q.conf import logger
@@ -24,3 +24,7 @@ def call_hook(sender, instance, **kwargs):
f(instance)
except Exception as e:
logger.error(_('return hook {} failed on [{}] because {}').format(instance.hook, instance.name, e))
pre_enqueue = Signal(providing_args=["task"])
pre_execute = Signal(providing_args=["func", "task"])
+3
View File
@@ -13,6 +13,7 @@ from django_q.conf import Conf, logger
from django_q.models import Schedule, Task
from django_q.humanhash import uuid
from django_q.brokers import get_broker
from django_q.signals import pre_enqueue
def async(func, *args, **kwargs):
@@ -43,6 +44,8 @@ def async(func, *args, **kwargs):
# finalize
task['kwargs'] = keywords
task['started'] = timezone.now()
# signal it
pre_enqueue.send(sender="django_q", task=task)
# sign it
pack = signing.SignedPackage.dumps(task)
if task.get('sync', False):