Runners¶
BaseCommandRunner
¶
Base class for command runners. Subclass and implement run().
Set supports_max_retries to True if the runner's task backend
supports per-task retry control (e.g. Celery's max_retries).
When False, a warning is logged if a command has max_retries > 0.
stop
¶
Request a graceful stop of a RUNNING execution.
The base implementation sets the cooperative stop_requested
flag (checked on the worker's output-flush heartbeat); backends
with a way to signal the worker process override this to also
send a SIGTERM-equivalent.
Source code in src/django_admin_runner/runners/__init__.py
force_stop
¶
Hard-kill the process running execution.
Returns True when a kill was performed. The base
implementation is a no-op (unsupported backend); runners whose
backend runs each task in its own process override this.
Source code in src/django_admin_runner/runners/__init__.py
finalize_stale
¶
Attribute why a dead worker's execution ended (best effort).
Called by the stale-run sweeper for RUNNING executions whose
worker_pid no longer exists. Returns (status, note) —
e.g. (TIMEOUT, "Killed by django-q2 timeout") — or None
when the backend has nothing to say (the sweeper then marks the
execution FAILED with a generic "worker lost" note). Must never
raise; wrap backend lookups defensively.
Source code in src/django_admin_runner/runners/__init__.py
create_schedule
¶
Materialize schedule into a native backend object.
Returns the backend reference to store in
ScheduledCommand.backend_schedule_key.
Source code in src/django_admin_runner/runners/__init__.py
update_schedule
¶
Update the native object referenced by backend_schedule_key in place.
Returns the (possibly new) backend reference.
Source code in src/django_admin_runner/runners/__init__.py
delete_schedule
¶
Remove the native object referenced by backend_schedule_key.
Source code in src/django_admin_runner/runners/__init__.py
schedule_next_run
¶
RunResult
dataclass
¶
RunResult(
execution: CommandExecution,
redirect_url: str,
is_async: bool,
backend: str,
task_id: str = "",
)
Returned by every BaseCommandRunner.run() implementation.
SyncCommandRunner
¶
DjangoTaskRunner
¶
CeleryCommandRunner
¶
Bases: BaseCommandRunner
Enqueues commands as Celery tasks.
Supports per-task retry control via Celery's autoretry_for and
max_retries on the shared task.
stop
¶
force_stop
¶
finalize_stale
¶
Attribute a swept execution via the Celery result backend.
REVOKED tasks (e.g. killed by a hard time_limit revoke) are
reported as TIMEOUT; FAILURE as FAILED. Best effort — an
unreachable broker yields None (generic FAILED).
Source code in src/django_admin_runner/runners/celery.py
DjangoQ2CommandRunner
¶
Bases: BaseCommandRunner
Enqueues commands as django-q2 tasks.
django-q2 does not support per-task retry control — max_retries
is ignored. Configure retries globally via Q_CLUSTER["max_attempts"].
stop
¶
Graceful stop: stop flag (heartbeat) + SIGTERM to the worker PID.
force_stop
¶
finalize_stale
¶
Attribute a swept execution via django-q2's Task records.
The q2 sentinel writes a failure record for tasks it killed
(e.g. for exceeding Q_CLUSTER["timeout"]). Best effort — a
missing/unreachable record yields None (generic FAILED).
Source code in src/django_admin_runner/runners/django_q2.py
get_runner
¶
Instantiate and return the runner configured by ADMIN_RUNNER_BACKEND.
Possible values:
- "django" (default) — :class:~django_admin_runner.runners.django_tasks.DjangoTaskRunner
- "sync" — :class:~django_admin_runner.runners.sync.SyncCommandRunner
- "celery" — :class:~django_admin_runner.runners.celery.CeleryCommandRunner
- "django-q2" — :class:~django_admin_runner.runners.django_q2.DjangoQ2CommandRunner
- dotted path — any :class:BaseCommandRunner subclass