Celery
v1.13.2 Apache-2.0z4j-celery ยท Upstream project
The industry standard, covered end-to-end.
Celery remote-control actions plus signal and broker-event dual capture. Broker-specific dead-letter replay is deliberately not advertised because a generic retry cannot consume or acknowledge the original DLQ entry.
- Latest
- v1.13.2
- Released
- 2026-10-29
- License
- Apache-2.0
Install
pip install z4j-celery Native actions
-
submit_task -
retry_task -
cancel_task -
bulk_retry -
purge_queue -
restart_worker -
pool_grow / pool_shrink -
add_consumer / cancel_consumer -
rate_limit
Not supported
- requeue_dead_letter (broker-specific DLQ consume/ack and routing required)
- list_dead_letters (no portable dead-letter store)
These are engine-level limitations: the underlying engine does not expose the primitives required to support these actions.
Wiring
How z4j plugs in
Event capture
Signals (in-process) + broker-events monitoring (fanout). Auto-switches based on worker pool type.
Reconciliation
celery.result.AsyncResult, authoritative; covers every backend (redis, rpc, db, etc.).
Install
Add z4j to a Celery app
z4j itself is one container or one Python process. The agent is a pip package in your app's environment that opens one outbound connection to it.
1. Run z4j
pip install z4j && z4j serve First boot prints a setup URL to stderr. Open it, create the first admin, and mint a token and HMAC secret for the agent. Docker and PostgreSQL setups are in the install guide.
Django + Celery
The most common stack we see. Django, Celery and django-celery-beat already cover execution and scheduling; z4j adds the operator layer on top: who retried what, why it failed last Tuesday, what is still queued, when a schedule last fired. z4j-django auto-detects your Celery app from cookiecutter, ROOT_URLCONF, WSGI or BASE_DIR layouts, so wiring is a single Z4J dict in settings.py.
2. Install the agent
pip install z4j-django[celery] 3. Wire it into Django
# settings.py
INSTALLED_APPS += ["z4j_django"]
Z4J = {
"brain_url": env("Z4J_BRAIN_URL"),
"token": env("Z4J_TOKEN"),
"hmac_secret": env("Z4J_HMAC_SECRET"),
"project_id": env("Z4J_PROJECT_ID"),
"agent_name": env("Z4J_AGENT_NAME", default=None),
}
# That's it. No CELERY_APP, no Z4J_DEV_MODE, no dev_mode kwarg.
# Auto-detect checks the documented candidate layouts. Add CELERY_APP when
# none of those candidates resolves your application. Full guide: Django integration and Celery engine docs.
Flask + Celery
The textbook way to add background work to a sync-heavy Python service. z4j-flask follows the standard extension shape (Z4J(app)) and finds your Celery app through app.config['CELERY_APP'] or app.extensions['celery']. No monkey-patching, no init-order tricks.
2. Install the agent
pip install z4j-flask[celery] 3. Wire it into Flask
from flask import Flask
from z4j_flask import Z4J
app = Flask(__name__)
app.config["CELERY_APP"] = "myapp.celery:app" # or register it in app.extensions["celery"]
z4j = Z4J(app) # reads Z4J_* from the environment or app.config["Z4J_*"] Celery workers start their own agent once the worker process imports z4j_celery; importing your Flask app module (which imports z4j_flask) does that. Full guide: Flask integration and Celery engine docs.
FastAPI + Celery
Running Celery from FastAPI is less common but legitimate, usually for a sync-heavy workload or a team moving off Django. Install z4j-fastapi[celery] and pass your Celery app to the lifespan hook.
2. Install the agent
pip install z4j-fastapi[celery] 3. Wire it into FastAPI
from myapp.celery import celery_app # your Celery app
from fastapi import FastAPI
from z4j_fastapi import z4j_lifespan
# The engine handle registers the Celery adapter in the web process.
app = FastAPI(
lifespan=z4j_lifespan(
celery_app=celery_app,
),
) Celery workers start their own agent once the worker process imports z4j_celery; importing your FastAPI app module (which imports z4j_fastapi) does that. Full guide: FastAPI integration and Celery engine docs.
Celery in a plain Python worker
2. Install the agent
pip install z4j-bare z4j-celery 3. Start it at worker boot
# worker.py
from z4j_bare import install_agent
from z4j_celery import CeleryEngineAdapter
# brain_url / token / hmac_secret / project_id come from the matching
# Z4J_* environment variables; pass them explicitly to skip the lookup.
runtime = install_agent(
engines=[CeleryEngineAdapter(celery_app=my_celery_app)],
)
try:
run_your_worker() # sync or async; the runtime is independent
finally:
runtime.stop() # stop the transport, close the local buffer Full guide: Plain Python integration and Celery engine docs.
Scheduler
Celery Beat with z4j
Native database scheduling for Django and Celery.
Celery Beat runs its schedules as Celery tasks. Supports inventory, create, edit, delete, enable, disable and immediate triggering for django-celery-beat PeriodicTasks. Static beat_schedule definitions support inventory and immediate triggering; edit those definitions in application configuration.
What z4j can do with Celery Beat
- List schedules
- Create schedule
- Update schedule
- Delete schedule
- Enable / disable
- Trigger-now
Limitations
- Requires matching z4j package versions on the server and in the producer
- Database writes require django-celery-beat and a connected scheduler process
- Static configuration is read-only except immediate triggering
Package z4j-celerybeat.
Reference: Celery Beat docs. For schedules edited from the dashboard on any engine, see z4j-scheduler; every option side by side is on the schedulers overview.
Included
What you get on top of Celery
- Persistent Celery task history in PostgreSQL or SQLite
- Task controls the adapter advertises, and nothing it cannot execute safely
- Issues: repeated failures grouped by fingerprint
- RBAC with invitations and password reset
- HMAC-chained audit log of operator actions
- Notifications: email, Slack, Telegram, webhook
The agent packages (z4j-celery and the framework adapters) are Apache 2.0. Importing them into your app does not affect its licensing. z4j itself is AGPL-3.0-or-later and runs in its own process.
More engines