Skip to content

signals

logger = get_logger() module-attribute

handle_after_task_publish(sender=None, body=None, headers=None, **kwargs)

Source code in tasks/signals.py
13
14
15
16
17
18
19
20
21
@signals.after_task_publish.connect
def handle_after_task_publish(sender=None, body=None, headers=None, **kwargs):
    if headers and 'id' in headers:
        try:
            instance = Task.objects.get(task_id=headers['id'])
            instance.state = TaskState.PENDING
            instance.save()
        except ObjectDoesNotExist:
            pass

handle_task_failure(sender=None, task_id=None, **kwargs)

Source code in tasks/signals.py
48
49
50
51
52
53
54
55
56
@signals.task_failure.connect
def handle_task_failure(sender=None, task_id=None, **kwargs):
    if task_id:
        try:
            instance = Task.objects.get(task_id=task_id)
            instance.state = TaskState.FAILURE
            instance.save()
        except ObjectDoesNotExist:
            pass

handle_task_postrun(sender=None, task_id=None, state=None, **kwargs)

Source code in tasks/signals.py
37
38
39
40
41
42
43
44
45
@signals.task_postrun.connect
def handle_task_postrun(sender=None, task_id=None, state=None, **kwargs):
    if task_id and state:
        try:
            instance = Task.objects.get(task_id=task_id)
            instance.state = TaskState.lookup(state)
            instance.save()
        except ObjectDoesNotExist as e:
            logger.exception(e)

handle_task_prerun(sender=None, task_id=None, **kwargs)

Source code in tasks/signals.py
24
25
26
27
28
29
30
31
32
33
34
@signals.task_prerun.connect
def handle_task_prerun(sender=None, task_id=None, **kwargs):
    if not task_id:
        return

    try:
        instance = Task.objects.get(task_id=task_id)
        instance.state = TaskState.STARTED
        instance.save()
    except ObjectDoesNotExist:
        pass

handle_task_revoked(sender=None, request=None, **kwargs)

Source code in tasks/signals.py
59
60
61
62
63
64
65
66
@signals.task_revoked.connect
def handle_task_revoked(sender=None, request=None, **kwargs):
    if request and request.id:
        try:
            instance = Task.objects.get(task_id=request.id)
            instance.delete()
        except ObjectDoesNotExist:
            pass

handle_task_update(sender, instance, created, **kwargs)

Source code in tasks/signals.py
69
70
71
72
73
74
@receiver(post_save, sender=Task)
def handle_task_update(sender, instance, created, **kwargs):
    send_to_group_sync(str('TASKS_GLOBAL'), {
        'type': 'task_updated',
        'message': str(instance.task_id)
    })