Add signals

Fixes #219
This commit is contained in:
Aurélien Bompard
2017-03-03 14:25:04 +01:00
parent 571676e59c
commit 77c5bb0737
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)