Skip to main content
arq logo

arq

v1.13.0 Apache-2.0

z4j-arq ยท Upstream project

Async Redis queue for FastAPI-era Python.

arq has no native re-enqueue-by-id primitive, so retry requires an explicit submit with the function name and complete inputs. Event capture chains onto arq's WorkerSettings on_job_start / on_job_end hooks.

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

Install

bash
pip install z4j-arq

Native actions

  • submit_task
  • cancel_task (Job.abort)

Not supported

  • retry_task
  • bulk_retry
  • requeue_dead_letter
  • list_dead_letters
  • purge_queue
  • restart_worker
  • 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

attach_to_worker_settings() chains onto on_job_start / on_job_end; it must be attached for lifecycle capture.

Reconciliation

arq.jobs.Job.status() + result_info(): clean deferred/queued/in_progress/complete mapping.

Install

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

2. Install the agent

bash
pip install z4j-django[arq]

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 arq
# worker process needs its own hook (see below).

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

Flask + arq

2. Install the agent

bash
pip install z4j-flask[arq]

3. Wire it into Flask

python
from flask import Flask
from z4j_flask import Z4J

app = Flask(__name__)
app.config["ARQ_REDIS_SETTINGS"] = "myapp.worker:redis_settings"
app.config["ARQ_FUNCTION_NAMES"] = ["my_task"]
z4j = Z4J(app)  # reads Z4J_* from the environment or app.config["Z4J_*"]

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

FastAPI + arq

The async-native pairing. arq's Redis-only footprint stays small, FastAPI's lifespan hook starts and stops the agent cleanly, and attach_to_worker_settings adds z4j's hooks to the arq worker.

2. Install the agent

bash
pip install z4j-fastapi[arq]

3. Wire it into FastAPI

python
from arq.connections import RedisSettings
from fastapi import FastAPI
from z4j_fastapi import z4j_lifespan

# The engine handle registers the arq adapter in the web process.
app = FastAPI(
    lifespan=z4j_lifespan(
        arq_redis_settings=RedisSettings(),
        arq_function_names=["my_task"],
    ),
)

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

arq in a plain Python worker

2. Install the agent

bash
pip install z4j-bare z4j-arq

3. Start it at worker boot

python
# worker.py, run with: python worker.py
from arq.connections import RedisSettings
from arq.worker import Worker
from z4j_arq import ArqEngineAdapter, attach_to_worker_settings
from z4j_bare import install_agent

async def my_task(ctx):
    ...

redis_settings = RedisSettings()
adapter = ArqEngineAdapter(redis_settings=redis_settings, function_names=["my_task"])
runtime = install_agent(engines=[adapter])

# keep_result > 0: completion capture reads the stored result.
worker = Worker(functions=[my_task], redis_settings=redis_settings, keep_result=3600)
attach_to_worker_settings(worker, adapter=adapter)  # attach before it runs
try:
    worker.run()
finally:
    runtime.stop()

Full guide: Plain Python integration and arq engine docs.

Scheduler

arq cron_jobs with z4j

Manage code-defined arq cron jobs with durable overrides.

arq cron_jobs runs its schedules as arq tasks. Binds to the actual arq Worker and applies durable dashboard create, edit, pause and delete operations. Native cron timing and task registration remain under application control.

What z4j can do with arq cron_jobs

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

Limitations

  • Requires matching z4j package versions and NativeScheduleControl on the actual Worker
  • Native cron only, using the worker's queue
  • Preserve the override file across restarts

Package z4j-arqcron. Reference: arq cron_jobs 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 arq

  • Persistent arq 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-arq 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 arq