Production Patterns
Patterns for running neops workers reliably at scale.
Container Deployment
A minimal Dockerfile for a worker:
FROM python:3.12-slim
WORKDIR /app
COPY pyproject.toml uv.lock ./
RUN pip install uv && uv sync --no-dev
COPY . .
CMD ["uv", "run", "neops_worker"]
Key considerations:
- Pin the Python version to match your development environment.
- The worker imports configuration from the project’s config module — ensure it is available in the container image.
- Use
.envfor configuration or inject environment variables via your orchestrator (Docker Compose, Kubernetes). - Exclude test code via
.dockerignorerather than selectiveCOPY.
Docker Compose
services:
worker:
build: .
environment:
URL_BLACKBOARD: http://workflow-engine:3030
DIR_FUNCTION_BLOCKS: ./my_function_blocks
WORKER_NAME: docker-worker-01
restart: unless-stopped
depends_on:
- workflow-engine
Scaling Workers
Horizontal scaling
Run multiple worker instances. Each worker:
- Registers independently with the workflow engine.
- Polls for jobs it can execute (based on registered function blocks).
- Processes one job at a time (
max_workers=1).
The workflow engine distributes jobs across available workers. To handle more concurrent work, add more worker instances. Throughput gives the jobs a worker runs per minute and how many workers a step over many devices needs.
Specialization
Different workers can register different function block packages:
| Worker | DIR_FUNCTION_BLOCKS |
Handles |
|---|---|---|
config-worker |
./config_blocks |
Config backup, push, compliance |
inventory-worker |
./inventory_blocks |
Discovery, inventory collection |
monitoring-worker |
./monitoring_blocks |
Health checks, SNMP polling |
This lets you scale each concern independently and isolate failures.
Workers per network zone
A worker takes only jobs in the network zones it serves, so each zone needs workers that run inside its network. Run at least two per zone: a rollback goes back to the zone its forward job ran in, and the worker it needs is often the one that just failed. A zone with a single worker also holds up its runs during every restart of that worker.
A worker inside network B, on host networking; 10.99.0.1 stands for an engine address
network B can reach:
docker run -d --name neops-worker-b --network host \
-e URL_BLACKBOARD=http://10.99.0.1:3030 \
-e DIR_FUNCTION_BLOCKS=neops/fb \
-e WORKER_NAME=neops-worker-b \
-e NEOPS_WORKER_NETWORK_ZONES=zone-b \
quay.io/zebbra/neops-worker-sdk:0.5.0
With Helm, one more release per zone, pinned to nodes inside that network. Every key under
env becomes an environment variable:
helm install neops-worker-b oci://quay.io/zebbra/charts/neops-worker --version 0.5.0 \
--set replicaCount=2 \
--set env.URL_BLACKBOARD=http://neops-neops-workflow-engine:3030 \
--set env.WORKER_NAME=neops-worker-b \
--set env.NEOPS_WORKER_NETWORK_ZONES=zone-b # escape commas for several zones: default\,zone-b
- Networking. A device address inside one of the worker host’s own networks is answered
there, by whatever runs on that host, and that answer receives the device’s credentials. On
a Docker host those networks include Docker’s default bridge (
172.17.0.0/16) and the compose address pools; in Kubernetes, the pod and service ranges. Run another zone’s workers on a host of their own inside that zone’s network, with host networking. On a shared Docker host, host networking does not get a worker out of Docker’s ranges: the bridges are routes on the host itself. A worker serves several zones only when their addresses do not overlap as seen from its host. - Reaching the engine. Keep the engine’s worker routes on a private network path. Giving a remote site’s workers such a path, for example a site-to-site VPN, is the operator’s job and outside Neops.
- The central workers serve the devices without a zone: set
NEOPS_WORKER_NETWORK_ZONES=defaulton them before the first zone is created.
Health Monitoring
Heartbeat
The worker sends heartbeats every HEARTBEAT_INTERVAL seconds, also while it drains a
job after a shutdown request. If the workflow engine stops receiving heartbeats for its
offline threshold (6 minutes by default), it marks the worker offline and fails the
in-flight job as worker-offline; it never re-queues a claimed job.
Container healthcheck
The worker removes HEALTH_FILE (default /tmp/neops-worker-alive) when it starts, so
a restarted container cannot report healthy from the previous process’s file, and again
when it stops, after its last heartbeat. Once it
polls, it touches the file at the start of every poll cycle, after every job, and on
every heartbeat tick. neops_worker_health exits 0 when that file is younger than
--max-age seconds (default: 3 × HEARTBEAT_INTERVAL) and 1 otherwise;
python -m neops_worker_sdk.cli.health is the same check.
The image declares this check as its HEALTHCHECK, so Docker and Docker Compose report
the worker’s health without any extra configuration:
HEALTHCHECK --interval=30s --timeout=10s --start-period=300s --retries=3 \
CMD ["/app/.venv/bin/neops_worker_health"]
To change the timings in Compose, override it (uv run --no-sync neops_worker_health
runs the same check):
services:
worker:
healthcheck:
test: ["CMD", "/app/.venv/bin/neops_worker_health"]
interval: 30s
timeout: 10s
start_period: 300s # covers an engine back during registration; raise it with the timeouts
retries: 3
The Helm chart (chart/neops-worker) runs the same command as a startupProbe (30 × 10 s,
the same 300 s budget as start_period) and a livenessProbe. Both are on by default and
are configured in values.yaml; set livenessProbe.enabled: false (or
startupProbe.enabled: false) to drop one. There is no readiness probe, since the worker
serves no traffic.
livenessProbe:
enabled: true
exec:
command: ["/app/.venv/bin/neops_worker_health"]
periodSeconds: 30
timeoutSeconds: 10
failureThreshold: 3
The probes need a writable, non-empty HEALTH_FILE. With readOnlyRootFilesystem: true,
mount an emptyDir at /tmp (or point HEALTH_FILE at a writable volume). An empty
HEALTH_FILE disables the file, and the probes then fail on every check.
Before it polls, the worker asks the engine twice about its version, each call waiting up
to API_REQUEST_TIMEOUT seconds (30 by default) on an engine that hangs. It then registers
itself and its function blocks, each retried for up to STARTUP_RETRY_TIMEOUT seconds (120
by default) while the engine is unreachable. With the defaults, 300 s covers an engine that
comes back while the worker registers. If you raise either timeout, raise start_period
(and the chart’s startupProbe.failureThreshold) with it, towards
2 x STARTUP_RETRY_TIMEOUT + 2 x API_REQUEST_TIMEOUT, or a worker waiting out an engine
restart is reported unhealthy before it ever polls.
The heartbeat tick refreshes the file whether or not the engine answers, so an engine
outage does not make a busy worker look dead: a job that is still running, or a result
the worker keeps re-sending for up to RESULT_PUSH_TIMEOUT, is not lost to a restart.
It does so only for HEALTH_STALL_TIMEOUT seconds (default 720) after the poll loop last
advanced. A job that hangs therefore turns the worker unhealthy once that time has passed
plus --max-age. The file shows that the worker process is advancing; it does not check
that the engine is reachable.
Who acts on unhealthy
Plain Docker Compose only reports the health status; it never restarts an unhealthy
container (restart: reacts to the process exiting). Restarting on unhealthy needs
an orchestrator that does it: Kubernetes (as a liveness probe), Docker Swarm, or a
helper such as autoheal.
A worker the engine has expired (its heartbeat gets a 404) exits with code 1 and
does not re-register on its own, so keep restart: unless-stopped (or on-failure)
as well: that restart is what brings it back.
Log-based monitoring
The worker logs structured events at key lifecycle points:
| Event | Level | Indicates |
|---|---|---|
NEOPS Worker starting... |
INFO | Worker initializing |
Found N function block(s) |
INFO | Discovery completed |
Registering worker with backend... |
INFO | Registration in progress |
Processing N job(s) |
INFO | Jobs received and processing |
Received SIGTERM. Shutting down... |
INFO | Graceful shutdown initiated |
Shutdown timeout of Ns elapsed with a job still running |
ERROR | The drain hit SHUTDOWN_TIMEOUT; the job’s outcome is unknown to the engine |
Result push for job … failed … retrying |
WARNING | The engine is unreachable; delivery is retried for up to RESULT_PUSH_TIMEOUT |
Client … is not compatible with workflow engine …; refusing to start. … |
ERROR | The engine refused the worker’s client version at the version check (for example an engine before 0.46); the worker exits 1 before it registers. The line says whether to upgrade the engine or run another SDK release |
This worker needs a workflow engine that routes by network zone, … |
ERROR | The engine is older than 0.46 or does not report networkZones.supported; the worker exits 1 before it registers. Upgrade the engine |
Worker registration failed |
ERROR | Cannot reach the workflow engine, it kept failing until STARTUP_RETRY_TIMEOUT, or it answered with a client error such as a 404 from a wrong URL_BLACKBOARD. When the engine itself refused the worker with a 400, such as for its network zones, or registered it for other zones, the line carries the engine’s reason without the hint to check URL_BLACKBOARD |
The engine refused this worker: … |
ERROR | The engine refused the worker’s client version (HTTP 426): the SDK does not match this engine. The line carries the engine’s reason, and the worker exits without retrying |
Worker expired! Backend rejected ping with 404. |
ERROR | Worker invalidated by backend |
Forward these logs to your monitoring stack (ELK, Grafana Loki, Datadog) for alerting.
Error Recovery
| Failure | Worker behavior | Engine behavior |
|---|---|---|
| Network partition | Misses heartbeats, reconnects on recovery; a finished job’s result is re-sent for up to RESULT_PUSH_TIMEOUT |
Marks worker offline after 6 min and fails its in-flight jobs as worker-offline (compensating reversible blocks); accepts a late result until then |
| Function block exception | Reports failure result to blackboard, without side_effects, with any rollback data already saved |
Assumes side effects; retries the step if the block is pure or idempotent. A step that fails for good makes the run FAILED_SAFE if it is pure, is rolled back if it is reversible, and otherwise makes the run FAILED_UNSAFE |
| Worker crash | Process exits | Fails the in-flight job as worker-offline after 6 min; never re-queues it |
| Workflow engine restart | Registration and result delivery are retried with backoff | Re-accepts worker registrations |
| Engine down at worker start | Retries registration for STARTUP_RETRY_TIMEOUT, then exits 1 |
— |
Security Considerations
- Credentials: Device credentials live in the CMS. Workers access them
through
WorkflowContext. Never store credentials in function block code or environment variables. - Network access: Workers need network access to both the workflow engine API and the managed devices. Use network segmentation to limit blast radius.
- TLS: Configure
URL_BLACKBOARDwithhttps://in production. The underlying HTTP client respects standard TLS settings. - Least privilege: Each worker only needs access to the devices its function blocks manage. Give each network its own workers and network zone, so a worker never reaches into another network’s address space.
- Zones route jobs; they do not authenticate workers: any worker that reaches the engine’s worker routes can register any zone and receive its devices’ credentials. Keep those routes on a private network path.

