Added admin pages for failures and success.

SAVE_LIMIT can now be set to limit the amount of saved tasks results.
This commit is contained in:
Ilan Steemers
2015-06-17 15:32:54 +02:00
parent 727a4d560d
commit e473665760
5 changed files with 138 additions and 27 deletions
+23 -16
View File
@@ -12,10 +12,10 @@ from django.utils import timezone
import redis
from django.core.signing import Signer, BadSignature
from django_q.apps import LOG_LEVEL, SECRET_KEY
from django_q.apps import LOG_LEVEL, SECRET_KEY, SAVE_LIMIT
from django_q.humanhash import uuid
from django_q.models import Task
from django_q.models import Task, Success
prefix = 'django_q'
q_list = '{}:q'.format(prefix)
@@ -23,7 +23,7 @@ signer = Signer(SECRET_KEY)
logger = logging.getLogger('django-q')
coloredlogs.install(level=getattr(logging, LOG_LEVEL))
r = redis.StrictRedis(decode_responses=True)
r = redis.StrictRedis()
class Cluster(object):
@@ -110,13 +110,7 @@ class Cluster(object):
logger.info("Finished [{}:{}]".format(func, name))
else:
logger.error("Failed [{}:{}] - {}".format(func, name, result))
Task.objects.create(name=name,
func=func,
task=task,
started=task[4],
stopped=task[5],
result=task[6],
success=success)
Cluster.save_task(task)
logger.info("{} stopped".format(name))
@staticmethod
@@ -134,12 +128,12 @@ class Cluster(object):
try:
task[0] = signer.unsign(task[0])
except BadSignature as e:
logger.error("Bad signature on task.")
task.append(timezone.now())
task.append(e)
task.append(False)
done_queue.put(task)
continue
task[0] = task[0].rsplit(":", 1)[0]
task.append(timezone.now())
task.append(e)
task.append(False)
done_queue.put(task)
continue
func = task[1]
module, func = func.rsplit('.', 1)
args = task[2]
@@ -169,6 +163,19 @@ class Cluster(object):
# Replace it with a fresh one
self.reincarnate(p.pid)
@staticmethod
def save_task(task):
if task[7] and 0 < SAVE_LIMIT < Success.objects.count():
Success.objects.first().delete()
Task.objects.create(name=task[0],
func=task[1],
args=task[2],
kwargs=task[3],
started=task[4],
stopped=task[5],
result=task[6],
success=task[7])
def stop(self):
# Send the STOP signal to the pool
self.running = False