mirror of
https://github.com/django-q2/django-q2.git
synced 2026-09-16 22:17:55 +08:00
Compare commits
2 Commits
v1.5.2
...
post-spawn
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35bea76ec3 | ||
|
|
4ba9e0338a |
@@ -39,7 +39,7 @@ from django_q.conf import (
|
|||||||
from django_q.humanhash import humanize
|
from django_q.humanhash import humanize
|
||||||
from django_q.models import Schedule, Success, Task
|
from django_q.models import Schedule, Success, Task
|
||||||
from django_q.queues import Queue
|
from django_q.queues import Queue
|
||||||
from django_q.signals import post_execute, pre_execute
|
from django_q.signals import post_execute, post_spawn, pre_execute
|
||||||
from django_q.signing import BadSignature, SignedPackage
|
from django_q.signing import BadSignature, SignedPackage
|
||||||
from django_q.status import Stat, Status
|
from django_q.status import Stat, Status
|
||||||
|
|
||||||
@@ -481,6 +481,7 @@ def worker(
|
|||||||
_("%(proc_name)s ready for work at %(id)s")
|
_("%(proc_name)s ready for work at %(id)s")
|
||||||
% {"proc_name": proc_name, "id": current_process().pid}
|
% {"proc_name": proc_name, "id": current_process().pid}
|
||||||
)
|
)
|
||||||
|
post_spawn.send(sender="django_q", proc_name=proc_name)
|
||||||
if setproctitle:
|
if setproctitle:
|
||||||
setproctitle.setproctitle(f"qcluster {proc_name} idle")
|
setproctitle.setproctitle(f"qcluster {proc_name} idle")
|
||||||
task_count = 0
|
task_count = 0
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ def call_hook(sender, instance, **kwargs):
|
|||||||
% {"hook": instance.hook, "name": instance.name, "error": str(e)}
|
% {"hook": instance.hook, "name": instance.name, "error": str(e)}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# args: proc_name
|
||||||
|
post_spawn = Signal()
|
||||||
|
|
||||||
# args: task
|
# args: task
|
||||||
pre_enqueue = Signal()
|
pre_enqueue = Signal()
|
||||||
|
|||||||
@@ -13,6 +13,12 @@ Before enqueuing a task
|
|||||||
The ``django_q.signals.pre_enqueue`` signal is emitted before a task is
|
The ``django_q.signals.pre_enqueue`` signal is emitted before a task is
|
||||||
enqueued. The task dictionary is given as the ``task`` argument.
|
enqueued. The task dictionary is given as the ``task`` argument.
|
||||||
|
|
||||||
|
After spawning a worker process
|
||||||
|
"""""""""""""""""""""""""""""""
|
||||||
|
|
||||||
|
The ``django_q.signals.post_spawn`` signal is emitted after a worker process has
|
||||||
|
spawned. The process name is given as the ``proc_name`` argument (string).
|
||||||
|
|
||||||
Before executing a task
|
Before executing a task
|
||||||
"""""""""""""""""""""""
|
"""""""""""""""""""""""
|
||||||
|
|
||||||
@@ -37,7 +43,7 @@ Connecting to a Django Q2 signal is done the same as any other Django
|
|||||||
signal::
|
signal::
|
||||||
|
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django_q.signals import pre_enqueue, pre_execute, post_execute
|
from django_q.signals import pre_enqueue, pre_execute, post_execute, post_spawn
|
||||||
|
|
||||||
@receiver(pre_enqueue)
|
@receiver(pre_enqueue)
|
||||||
def my_pre_enqueue_callback(sender, task, **kwargs):
|
def my_pre_enqueue_callback(sender, task, **kwargs):
|
||||||
@@ -51,4 +57,8 @@ signal::
|
|||||||
def my_post_execute_callback(sender, task, **kwargs):
|
def my_post_execute_callback(sender, task, **kwargs):
|
||||||
print(f"Task {task['name']} was executed with result {task['result']}")
|
print(f"Task {task['name']} was executed with result {task['result']}")
|
||||||
|
|
||||||
|
@receiver(post_spawn)
|
||||||
|
def my_post_spawn_callback(sender, proc_name, **kwargs):
|
||||||
|
print(f"Process {proc_name} has spawned")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user