Skip to main content
RQ logo

RQ

v1.13.0 Apache-2.0

z4j-rq ยท Upstream project

Lightweight Redis queue, fully instrumented.

RQ's worker model has no remote-control channel, but every data-plane action is implemented: retry, cancel, bulk retry, purge, dead-letter listing and requeue, plus worker-wrap event capture.

Latest
v1.13.0
Released
2026-10-19
License
Apache-2.0

Install

bash
pip install z4j-rq

Native actions

  • submit_task
  • retry_task
  • cancel_task
  • bulk_retry
  • purge_queue
  • requeue_dead_letter
  • list_dead_letters

Not supported

  • restart_worker (RQ workers have no remote-control channel; restart them with your process manager)
  • rate_limit

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

Worker-wrap monkey-patch plus per-job callbacks. No code changes required in your jobs.

Reconciliation

rq.job.Job: status + ended_at + exc_info from the Redis hash.

Install

Add z4j to a RQ 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

bash
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 + RQ

Django and RQ via django-rq is a clean, focused stack. z4j adds Postgres-backed history (RQ's Redis-resident records have a TTL), bulk requeue and RBAC across several Django projects. z4j-rq wraps the RQ worker's execute_job (started by register_worker_bootstrap in the worker), so your jobs need no changes.

2. Install the agent

bash
pip install z4j-django[rq]

3. Wire it into Django

python
# 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),
}
# z4j-django discovers only Celery in the web process; the RQ
# worker process needs its own hook (see below).

Task lifecycle events come from the RQ worker process, which needs the z4j-rq worker hook. Full guide: Django integration and RQ engine docs.

Flask + RQ

2. Install the agent

bash
pip install z4j-flask[rq]

3. Wire it into Flask

python
from flask import Flask
from z4j_flask import Z4J

app = Flask(__name__)
app.config["RQ_REDIS_URL"] = "redis://localhost:6379/0"
z4j = Z4J(app)  # reads Z4J_* from the environment or app.config["Z4J_*"]

Task lifecycle events come from the RQ worker process, which needs the z4j-rq worker hook. Full guide: Flask integration and RQ engine docs.

FastAPI + RQ

2. Install the agent

bash
pip install z4j-fastapi[rq]

3. Wire it into FastAPI

python
from redis import Redis
from fastapi import FastAPI
from z4j_fastapi import z4j_lifespan

# The engine handle registers the RQ adapter in the web process.
app = FastAPI(
    lifespan=z4j_lifespan(
        rq_app=Redis(),
    ),
)

Task lifecycle events come from the RQ worker process, which needs the z4j-rq worker hook. Full guide: FastAPI integration and RQ engine docs.

RQ in a plain Python worker

2. Install the agent

bash
pip install z4j-bare z4j-rq

3. Start it at worker boot

python
# A module your RQ worker imports (for example rq_settings.py)
from z4j_rq import register_worker_bootstrap

# Reads Z4J_BRAIN_URL / Z4J_TOKEN / Z4J_PROJECT_ID / Z4J_HMAC_SECRET and
# Z4J_RQ_REDIS_URL from the environment, then starts the agent with an
# RqEngineAdapter. A second call in the same process is a no-op.
register_worker_bootstrap()

Full guide: Plain Python integration and RQ engine docs.

Scheduler

rq-scheduler with z4j

Persistent dashboard management for native RQ schedules.

rq-scheduler runs its schedules as RQ tasks. Manages rq-scheduler definitions and pause state in Redis. Every producer sharing the registry must install managed native control; edits and native dispatch share Redis transactions.

What z4j can do with rq-scheduler

  • List schedules
  • Create schedule
  • Update schedule
  • Delete schedule
  • Enable / disable
  • Trigger-now

Limitations

  • Requires matching z4j package versions and managed control on every producer
  • Use Redis persistence for state across Redis restarts
  • Existing queued work can finish after a pause

Package z4j-rqscheduler. Reference: rq-scheduler 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 RQ

  • Persistent RQ 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
License

The agent packages (z4j-rq 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

Other z4j engines

Try z4j with RQ