Browse Source

[Bugfix] 修复小bug

pull/1171/head
ibuler 7 years ago
parent
commit
1d7ba3e204
  1. 10
      apps/ops/celery/signal_handler.py

10
apps/ops/celery/signal_handler.py

@ -3,6 +3,7 @@
import os
import datetime
import sys
import time
from django.conf import settings
from django.utils import timezone
@ -53,10 +54,19 @@ def after_task_publish_signal_handler(sender, headers=None, **kwargs):
CeleryTask.objects.create(
id=headers["id"], status=CeleryTask.WAITING, name=headers["task"]
)
cache.set(headers["id"], True, 3600)
@task_prerun.connect
def pre_run_task_signal_handler(sender, task_id=None, task=None, **kwargs):
time.sleep(0.1)
for i in range(5):
if cache.get(task_id, False):
break
else:
time.sleep(0.1)
continue
t = get_object_or_none(CeleryTask, id=task_id)
if t is None:
logger.warn("Not get the task: {}".format(task_id))

Loading…
Cancel
Save