Worker Lifecycle
The neops worker is a long-running process that discovers function blocks, registers them with the workflow engine, and continuously polls for jobs.
Startup Sequence
sequenceDiagram
participant W as Worker
participant FS as File System
participant WE as Workflow Engine
W->>W: Load environment (.env)
W->>WE: POST /version/compatibility/
WE-->>W: compatible, deprecated
W->>WE: GET /version
WE-->>W: networkZones.supported
W->>FS: Scan DIR_FUNCTION_BLOCKS directories
FS-->>W: Discovered function block modules
W->>W: Import modules (triggers @register_function_block)
W->>WE: Register worker (name, IP, networkZones)
WE-->>W: worker_id, networkZones
W->>WE: Register function blocks (schemas, metadata)
W->>W: Start heartbeat task
W->>W: Start job polling task
1. Version check
The worker sends its engine client’s version to POST /version/compatibility/:
- an answer of
compatible: falseends the worker with exit code 1. While the engine is 0.x it accepts only a client of its own minor, so an engine other than0.47answers that for this SDK’s client, and the worker names both ways out: Client 0.47.0 is not compatible with workflow engine v0.46.0; refusing to start. Upgrade the engine to 0.47, or run the SDK release built for workflow engine v0.46.0. The engine also answerscompatible: falsefor a client version it has withdrawn; the message then ends Run the SDK release built for workflow engine <version>.; - an engine that cannot be asked gets the benefit of the doubt: the worker logs a warning
and starts. That covers an unreachable engine, a timeout, an error status such as a
404from an engine without the route (one before0.41.12; the zone check below then stops the worker), and an answer it cannot read. Such a worker can still be incompatible: registration or the first job shows it.
A deprecated client only gets a warning.
The worker then asks GET /version whether the engine routes jobs by network zone. Every
job this SDK polls carries the zone fields, so it needs workflow engine 0.46 or later
whether or not the worker serves zones. An engine whose answer lacks
networkZones.supported: true ends the worker with exit code 1 and the message This
worker needs a workflow engine that routes by network zone, 0.46 or later; the engine at
<URL_BLACKBOARD> is <version>. An engine that cannot be asked gets a warning, and
the worker starts.
2. Discovery
The worker scans directories listed in DIR_FUNCTION_BLOCKS (comma-separated
paths). For each directory, it recursively imports all Python modules. Import
triggers the @register_function_block decorator, which adds the class and
its registration metadata to the global registry.
3. Registration
The worker registers itself with the workflow engine via the blackboard API,
with the network zones it serves, receiving a worker_id.
It then sends all discovered function block registrations — including
parameter/result JSON schemas, version information, and purity/idempotency flags.
A refused registration ends the worker with exit code 1, without a retry. Workflow engine
0.45 or later applies the version check to the registration too and answers 426 for a
client it refuses, also when the check in step 1 could not be asked; the worker then logs The
engine refused this worker: <the engine’s reason>. The engine’s own refusal, a 400 such
as one of the worker’s network zones, logs Worker registration failed: <the engine’s
message>. Any other client error, such as a 404 or 405, comes from a wrong URL or a proxy
and adds Check URL_BLACKBOARD and any proxy in front of the engine.
4. Concurrent Tasks
Two async tasks run concurrently on the main event loop:
| Task | Interval | Purpose |
|---|---|---|
| Heartbeat | HEARTBEAT_INTERVAL (default 20s) |
Keeps the worker marked as online in the workflow engine |
| Job polling | at once after a job; POLL_INTERVAL (default 10s) after an empty or failed poll |
Fetches pending jobs from the blackboard |
Job Execution
When the polling task receives jobs:
- Match
job.function_block_idagainst the local registry. - Build the job’s
JobMeta: its zone fields from the poll’smeta, its identity from the job’s own fields, and the worker from its registration. - Submit the job to a
ThreadPoolExecutorwithmax_workers=1. - Inside the worker thread, call
asyncio.run()to execute the function block (this gives each job its own event loop). - Start blocking detection monitoring on the main loop.
- Collect the result and report it back to the blackboard.
Sequential Processing
Jobs are processed one at a time (max_workers=1). This avoids:
- Connection exhaustion on shared devices.
- Race conditions in context data.
- Unpredictable resource usage.
If the workflow engine pushes multiple jobs, they are queued and executed in order.
Job Types
| Type | Method called | Purpose |
|---|---|---|
ACQUIRE |
acquire() |
Lock resources and expand context |
EXECUTE |
execute_function_block() → run() |
Main function block logic (wrapped with error boundaries). The result carries sideEffects only when it is False, and the rollback data the block saved, also after an exception. A pure block whose result claims side effects is failed instead, with retryable=False. A failure before run() was entered gets side_effects=False and retryable=False |
ROLLBACK |
rollback_function_block() → rollback() |
Undo this step’s changes when the run failed; the job mirrors the forward job’s parameters and context and carries forwardResult, which the worker parses into the block’s ForwardResult (data and rollback data by alias). A missing or unparseable forwardResult fails the job with retryable=False without calling rollback(). The default rollback() returns failure — override it in every block registered reversible=True |
Network zones
A network zone is a network that only its own workers reach; zones may reuse each other’s
addresses, for example two sites whose devices share the range 10.0.0.0/24. Every device
in the CMS is in one zone, and a device without one is in default. The engine hands a job
only to a worker that serves the job’s zone, so a worker must run where it reaches that
zone’s devices.
NEOPS_WORKER_NETWORK_ZONES lists the zones a worker serves. On startup the worker:
- runs the version check, as every worker does: it ends on an engine that does not route by zone. An engine that cannot be asked at all is left to the registration below;
- registers with its zones (
networkZones):- a
400ends the worker with the engine’s message. The engine sends it for a zone the CMS does not hold, and for a worker without zones once the CMS holds a zone besidesdefault; - a
503means the engine has not read the zones from the CMS since it first started. The worker retries, as for an unreachable engine, forSTARTUP_RETRY_TIMEOUTseconds; - an answer that registers other zones than the worker asked for, or no zones at all (an
engine before
0.46), ends the worker after it unregisters again. A worker withoutNEOPS_WORKER_NETWORK_ZONESexpectsdefaultback.
- a
Each job’s meta names the zone the job runs in
and the zones its worker serves; job log lines carry the zone as network_zone.
Several zones on one worker
List several zones only if their addresses do not overlap as this host sees them. A
worker that serves zone-a and zone-b reaches 10.0.0.1 in only one of them, and a
job meant for the other zone’s 10.0.0.1 logs in to the wrong device with that device’s
credentials.
How workflows place jobs into zones (the step’s networkZone, override, and the zone of a
job’s device) is described in the engine’s
Network Zones page.
Graceful Shutdown
The worker handles SIGINT and SIGTERM signals:
- Set the shutdown event: no new polls. A job the last poll already returned still runs to its result, because it is claimed by this worker and the engine cannot release it.
- Keep the heartbeat running while the current job finishes, so the engine does not declare the worker offline mid-job.
- Wait at most
SHUTDOWN_TIMEOUTseconds for the running job. - Stop the heartbeat and deregister the worker from the workflow engine.
- Exit with code 0, or with code 1 when the timeout elapsed.
A job left behind is not re-queued
When SHUTDOWN_TIMEOUT elapses the worker logs that the job’s outcome is unknown,
deregisters, and ends its process at once. A thread cannot be cancelled, so the job is
stopped wherever it is, possibly with a device change half applied; ending the process is
what keeps it from running on while the engine compensates it elsewhere. The engine
never re-queues a claimed job: its cleanup fails the job as worker-offline and treats
it as possibly executed, so a reversible block is rolled back and an irreversible one
ends the run FAILED_UNSAFE for a human to resolve. Size the timeout for your longest
job, and keep the orchestrator’s termination grace period above it.
Worker Expiry
If the worker fails to send heartbeats (e.g., network partition), the workflow engine marks it as expired.
- The next heartbeat attempt receives a
404, causingWorkerExpiredError. - The worker logs the error and shuts down (exit code 1).
- Jobs that were in-flight are failed by the engine as worker-offline (never re-queued) and compensated where the block is reversible.
The worker does not attempt to re-register automatically. Use your
orchestrator’s restart policy (Docker restart: unless-stopped, Kubernetes
restartPolicy: Always) to bring it back.
Upgrading Past Re-Versioned Base Blocks
A worker serves exactly the block versions its SDK registers, and the engine resolves a workflow step to the exact version it pins. The release that adds side_effects and rollback data moves seven base blocks from 0.1.0 to 0.1.1:
fb.base.neops.io/device_update_device,group_update_group,global_add_devicesandglobal_add_groupsare now registered pure, because declareddb_updatesare not side effects.fb.base.neops.io/network_device_apply_configuration,network_device_parse_command_outputandnetwork_device_reloadnow reportside_effects=Falsewhen they refuse before touching the device.
fb.base.neops.io/network_device_apply_configuration then moves on to 0.2.0: it is registered reversible=True and records the device’s running and startup configuration before changing it, which its rollback() writes back when the workflow fails. Definitions pinning 0.1.1 need the same treatment as below.
Symptom. A stored workflow definition that still pins one of these at 0.1.0 keeps starting, and it takes its CMS locks. But once no worker registers 0.1.0, its job stays pending. The engine fails it after BLACKBOARD_PENDING_JOB_TIMEOUT, 60 minutes by default.
Fix, before you replace the workers. Pick one:
- Republish each affected definition with the pin moved to
0.1.1. Bump the workflow’s own version as well: published content is immutable. - Keep one worker on the previous SDK image until the runs pinned to
0.1.0have drained.
Order. Upgrade the workflow engine first, then the workers; an older worker keeps working against the newer engine. To roll back, do it the other way round: workers first, then the engine.
Upgrading to network zones
SDK 0.5.0 serves network zones. It needs workflow engine 0.46 or later, and on 0.x the
engine accepts only clients of its own minor version. Unlike the
base-block upgrade above, an older worker does not
keep working against the newer engine once it restarts. The order for the whole platform
(runs, core, engine, workers, zones), and what goes wrong on the core and engine side out of
order, is on the engine’s
Upgrading to 0.46.
The worker side of it:
- Replace every worker with SDK
0.5once the engine runs0.46. - Set
NEOPS_WORKER_NETWORK_ZONES=defaulton the workers that serve the central network, in their own service definition. Once a zone exists, the engine refuses every worker without the setting at its next start. - Start each zone’s workers once their zones exist in the CMS. The engine refuses a worker that names a zone the CMS does not hold yet.
Out of order, on the worker side:
- a worker on SDK
0.5against engine0.45exits 1 at its version check on every start, until the engine is upgraded; - a worker on SDK
0.4keeps running against engine0.46until it restarts; restarted, it stops at its version check and exits 1 with Client 0.45.0 is not compatible with this engine. Update the SDK. Only when that check cannot reach the engine does the registration refuse it instead, with The engine refused this worker: ….
Going back. Going back below core 2.4.0 deletes every zone and every device’s zone; see
core’s notes on going back below 2.4.0.
No order keeps the workers running across the engine’s minor version, so go back in one
stop: let every run finish, stop the workers, take the engine back to 0.45 (see the engine’s
Going back to 0.45
for its migration), then core, if you go below 2.4.0, and then start the workers on SDK 0.4.
The engine goes back before core; the engine’s
Going back to 0.45
says why.
Base blocks. Four base blocks are re-versioned. A stored definition that pins an old version keeps starting and its job stays pending, as in the base-block upgrade above: republish it with the new pins. A worker on the previous SDK cannot serve the old versions once it is replaced, so runs pinned to them have to finish before the upgrade starts.
| Block | From | To | What changes |
|---|---|---|---|
fb.base.neops.io/global_discover_network |
0.1.0 |
0.2.0 |
Creates devices in the job’s zone and recognises them by IP inside that zone; each device_identifiers entry is paired with the zone, and network_zone is refused as an entry |
fb.base.neops.io/global_add_devices |
0.1.1 |
0.2.0 |
Takes an optional network_zone per device, else the job’s zone, and recognises devices by IP inside that zone |
fb.base.neops.io/device_update_device |
0.1.1 |
0.2.0 |
Takes an optional network_zone, which moves the device |
fb.base.neops.io/network_device_get_interfaces |
0.1.0 |
0.1.1 |
Names its device by id, so its interfaces bind to that device also on an override job |
Your own blocks. A block that creates a device must now set network_zone, and an
interface that names its device without an id must name the device’s zone and its hostname
or IP; see
Creating Entities. Both fail the
job otherwise. identifier_fields takes groups now; a list of bare fields keeps working,
each field being a group of one.
Upgrading to SDK 0.6
fb.base.neops.io/network_device_save_configuration moves from 0.1.0 to 0.1.1; it does
the same thing. SDK betas up to 0.2.0-beta.7 registered 0.1.0 as pure, later releases as
not pure, and workflow engine 0.44 or later refuses to re-register an exact version with a
different isPure. An engine that last saw 0.1.0 from such a beta refused every newer
worker with Function block fb.base.neops.io/network_device_save_configuration:0.1.0 is
already registered with different isPure: register a new version instead. A stored
definition pinning 0.1.0 stays pending as in the
base-block upgrade above: republish it with
0.1.1.

