Background jobs and workers
Periodic and deferred work in FireHawk runs as durable jobs stored in PostgreSQL and processed by workers. Workers use the same image as the API with a different command (python -m app.worker).
What runs as a job
Section titled “What runs as a job”| Job | What it does |
|---|---|
| Drift check | Compares a deployed host’s live firewall with its baseline, every DRIFT_CHECK_INTERVAL_MINUTES (default 30) and on demand from the Jobs page |
| Dynamic alias refresh | Fetches URL feeds, DNS names, GeoIP and cloud ranges on each alias’s schedule and pushes changed sets to the hosts using them |
| Safe-deploy check | Asks a host for the outcome of a safe deploy after FireHawk lost the connection, and keeps asking every minute until the host answers |
| Rollout steps and hosts | Deploys the batches of a rollout, one job per host |
| Rule expiry | Removes temporary rules when they end and deploys the affected hosts |
| Credential rotation | Installs and verifies a new SSH key on every host using a credential |
| Notification delivery | Sends events to e-mail, Slack, Teams or webhooks, with retries |
Requests that must answer with a result, such as a deploy, a preview or a manual drift check from a host page, still run directly in the API request.
How jobs behave
Section titled “How jobs behave”- Durable. Jobs survive restarts of the API and the workers.
- One at a time per host. Two jobs for the same host never run at once, and duplicate jobs (for example two drift checks of one host) are not queued twice.
- Retries. A failing job is retried with an increasing delay (30 seconds, doubling, up to 15 minutes) until its attempts run out; then it is failed and, if configured, a job failed notification is sent.
- Worker loss. A worker heartbeats every 10 seconds. If one dies without shutting down cleanly, its running jobs are handed to another worker once their lease of 120 seconds expires.
- Clean shutdown. On SIGTERM a worker cancels its running jobs and puts them back in the queue, so stopping or upgrading workers loses nothing. Give it time to stop (the Compose file uses a 30 second grace period).
- One scheduler. Every worker can schedule due work (drift checks, alias refreshes, expiries) every 30 seconds, but a database lock makes sure only one of them does it at a time.
- Retention. Finished, failed and cancelled jobs are deleted after
JOB_RETENTION_DAYS(default 7).
Sizing and scaling
Section titled “Sizing and scaling”Each worker runs up to WORKER_CONCURRENCY jobs at the same time (default 8). Most jobs wait on SSH, so a worker handles many hosts. Add workers when the queue builds up (the Jobs page shows the oldest waiting job) or for redundancy.
Docker Compose:
docker compose up -d --scale worker=3Set WORKER_CONCURRENCY in .env to change the slots per worker.
Helm:
worker: replicaCount: 3 concurrency: 8Workers need the same network access to managed hosts as the API (SSH, jump hosts), plus outbound access for alias feeds and notification endpoints.
The Jobs page
Section titled “The Jobs page”Users with the jobs.view permission see the Jobs page:
- workers seen in the last hour, with their busy slots,
- queued and running jobs, the oldest waiting job, outcomes of the last 24 hours,
- every job with its status, kind, host, attempts and error, filterable by status and kind.
With jobs.manage, failed or cancelled jobs can be retried, queued or running jobs cancelled, and Check drift on all hosts queues a drift check for every host. See Audit log and jobs.
When no worker runs
Section titled “When no worker runs”Jobs are queued but nothing processes them: drift checks stop, dynamic aliases are not refreshed, rollouts do not start, rule expiries and notifications wait, and safe deploys that lost their host are not checked automatically. The Jobs page warns No worker is running.
Start the workers again:
docker compose up -d workerQueued jobs then run. Interactive actions in the UI (previews, deploys, rollbacks) keep working without workers.
Single-container setups
Section titled “Single-container setups”The API can run a worker inside its own process. This is controlled by RUN_WORKER, which defaults to true. The provided Compose file and Helm chart set RUN_WORKER=false on the API because they run dedicated workers.
If you run only the API container (no separate worker), leave RUN_WORKER unset or true so that background jobs still run. Do not combine an embedded worker with many API replicas unless you want every replica to process jobs; that is safe, but separate workers are easier to size and monitor.
