-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex01_basic_enqueue.py
More file actions
executable file
·36 lines (24 loc) · 970 Bytes
/
ex01_basic_enqueue.py
File metadata and controls
executable file
·36 lines (24 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env -S uv run
"""enqueue a task and inspect the ready queue."""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import _settings
from _example import result, status_name, step, takeaway, title
from django.tasks import task
from dj_queue.models import Job, ReadyExecution
@task
def greet(name):
return f"hello, {name}"
title("ex01", "enqueue a task and inspect the ready queue")
step(1, "enqueue one task through the backend")
task_result = greet.enqueue("world")
result(
f"backend={_settings.DB_BACKEND} job_id={task_result.id} status={status_name(task_result.status)}"
)
step(2, "read the stored job and ready execution rows")
job = Job.objects.get(pk=task_result.id)
result(f"task_path={job.task_path}")
result(f"payload={job.payload}")
result(f"ready={job.ready} ready_executions={ReadyExecution.objects.count()}")
takeaway("enqueue writes the job row immediately and places the job in the ready queue")