Operations Reference
This reference defines the fields, steps, statuses, and API actions of fleet operations. Fleet Operations explains the model, and Run a Fleet Operation walks through an example.
Operation
fleet_CreateOperation creates an operation as a draft:
{
"projectId": "p_...",
"name": "Collect uptime",
"enrollment": "Snapshot",
"deadlineSecs": 86400,
"selector": {
"groups": { "none": ["d_group_..."] },
"expression": "properties[\"dev.nexigon.ota.status\"].value.state == \"completed\""
},
"stages": [
{ "name": "Canary", "percentage": 10 },
{ "name": "Everything", "guard": { "minCompletedPercent": 100 } }
],
"steps": [{ "kind": "DeviceCommand", "command": "uptime", "input": {} }]
}
| Field | Description |
|---|---|
projectId | Project whose devices the operation can select. |
name | Name, 1 to 128 characters. |
description | Optional description, up to 4096 characters. |
enrollment | Snapshot selects the targets once, when the operation starts. Dynamic also selects devices that match later, until the operation is closed. Defaults to Snapshot. |
deadlineSecs | Time that each target has to finish after its release, from 1 second to 30 days. A target that has not finished in time times out. Without a deadline, targets wait indefinitely. |
selector | Target selector. |
stages | 1 to 20 stages in the order of their release. |
steps | 1 to 64 steps that each target runs. |
Operations cannot be changed after they are created.
Target Selection
The selector decides which devices of the project become targets. All supplied conditions must hold:
| Field | Description |
|---|---|
deviceIds | Devices that may match. Without this field, every device of the project may match. |
groups | Group conditions with all, any, and none. |
expression | Expression over properties and now that must be true, up to 4096 characters. |
A device for which the expression produces an error is not selected. Nexigon
Hub records a selection error for it instead, which
fleet_QueryOperationSelectionErrors lists. A dynamic operation evaluates the
selector for the device again when it next selects targets, which it does
periodically on an interval of the instance. Selection errors that remain when
the operation finishes make it fail. A device that stops matching keeps its
target.
fleet_PreviewOperationTargets evaluates a selector against the current
devices of a project without creating an operation. It returns the number of
matching devices as matchingCount, the newest of them as devices, and the
devices for which the expression produced an error as errorCount and
selectionErrors. The optional limit, from 1 to 1000 and 20 by default,
bounds both lists. The count covers the whole selection, before stages apply.
Stages
Fleet operations use the stages of profile rollouts:
| Field | Description |
|---|---|
name | Name, 1 to 128 characters. |
groups | Group conditions that the stage’s targets satisfy. Without conditions, every target satisfies them. |
percentage | Share of the targets that satisfy the conditions, by their position, above 0 and up to 100. Defaults to 100. |
spreadSecs | Time over which the stage releases its targets, up to 30 days. Defaults to 0. |
guard | Conditions for releasing the stage: minCompletedPercent, maxFailedPercent, and soakSecs. The first stage ignores it. |
A device belongs to the first stage whose group conditions it satisfies and whose percentage is above its position. A device that belongs to no stage does not become a target. Releasing Stages describes spreads, guards, and their defaults. For a guard, a target has completed once it succeeded and failed once it failed or timed out. Cancelled targets and targets of deleted devices do not count.
Steps
Each target runs the steps in order. Every step accepts an optional when
expression: the step runs if it is true, is skipped if it is
false, and fails if it produces an error.
SetDeviceProperty
Sets the device’s own value of a property:
{
"kind": "SetDeviceProperty",
"name": "com.example.sensor.config",
"value": { "sample_rate_hz": 10 },
"protected": true
}
protected defaults to false. The device’s own value applies over the values
of its profiles.
PatchDeviceProperty
Applies a JSON merge patch to the
device’s own value of a property, or to null if the device has no own value:
{
"kind": "PatchDeviceProperty",
"name": "com.example.sensor.config",
"patch": { "debug": true }
}
Without protected, the property keeps its protection, and a new property is
unprotected.
RemoveDeviceProperty
Removes the device’s own value of a property. The values of the device’s profiles still apply afterward:
{ "kind": "RemoveDeviceProperty", "name": "com.example.sensor.config" }
WaitForDeviceProperty
Waits until the device’s properties satisfy expression:
{
"kind": "WaitForDeviceProperty",
"expression": "properties[\"com.example.sensor.state\"].value.configVersion >= operation.writes[\"com.example.sensor.config\"].version",
"failureExpression": "properties[\"com.example.sensor.state\"].value.error != null",
"timeoutSecs": 1800
}
The step succeeds once expression is true and fails once
failureExpression is true, which takes precedence. While an expression
produces an error, for example because the device has not reported a property
yet, the step keeps waiting and shows the error. timeoutSecs, from 1 second
to 30 days, times the step out. Without it, the step waits until the
operation’s deadline, if any.
DeviceCommand
Asks the device to run a device command:
{
"kind": "DeviceCommand",
"command": "uptime",
"input": {},
"timeoutSecs": 300
}
The command must be in the device’s command manifest, and the device must meet
the device requirements. timeoutSecs, from 1 second
to 1 day and one hour by default, starts when the device claims the command and
is also the timeout of the command handler on the device. Use the operation’s
deadline to limit the wait for an offline device.
The input and the stored output can each have up to 64 KiB, encoded as compact JSON. For a larger output, Nexigon Hub stores only its size. Property values and patches have the same limit. Operators of self-hosted instances can change these limits.
Expressions
Step expressions read the variables properties
and now, like selectors, and also operation. For each property that an
earlier step of the operation wrote on the device,
operation.writes[name].version holds the property version that the write
created. A wait can compare it with a version that the device reports, so that
it reacts to the operation’s own write rather than an earlier change.
Nexigon Hub parses expressions when an operation is created and rejects invalid ones. It checks types only during evaluation.
Statuses
| Operation Status | Meaning |
|---|---|
Draft | Created but not started. |
Running | The operation selects targets, releases stages, and hands out work. |
Halted | The operation does none of these until it is resumed. |
Completed | All targets finished, none failed or timed out, and no selection errors remain. |
Failed | All targets finished, but some failed or timed out, or selection errors remain. |
Cancelled | The operation was cancelled. |
An operation finishes once it selects no further targets, all of its stages are released and their spreads have passed, and all targets of existing devices have finished. A snapshot operation selects no further targets after it starts, and a dynamic operation once it is closed.
| Target Status | Meaning |
|---|---|
Pending | The target has not been released yet. |
Running | The target runs its steps. |
Succeeded | The target finished all steps. |
Failed | A step failed. |
TimedOut | A step’s timeout or the operation’s deadline passed. |
Cancelled | The operation was cancelled, or the target’s device was deleted. |
Steps have the statuses Pending, Running, Succeeded, Failed,
TimedOut, and Skipped. Nexigon Hub checks timeouts and deadlines every 20
seconds, so a step can time out shortly after its time has passed.
Halting
Halting an operation stops it from selecting targets, releasing stages, and handing out work. Devices can still report the results of commands that they already claimed. The clocks of spreads, soak times, timeouts, and deadlines do not advance while the operation is halted.
API Actions
| Action | Purpose |
|---|---|
fleet_QueryOperations | List the operations of a project, newest first. |
fleet_GetOperation | Get an operation with its selector, steps, and the progress of its stages. |
fleet_QueryOperationTargets | List the targets by stage, optionally by status, with pagination. |
fleet_QueryOperationSelectionErrors | List the devices for which the selector produced an error. |
fleet_PreviewOperationTargets | Count and list the devices that a selector currently matches. |
fleet_CreateOperation | Create a draft operation. |
fleet_StartOperation | Start a draft, which selects the targets and releases the first stage. |
fleet_HaltOperation | Halt a running operation. |
fleet_ResumeOperation | Resume a halted operation where it stopped. |
fleet_ReleaseOperationStage | Release the next stage, given by stageIndex, skipping its guard and the wait for the previous stage’s spread. |
fleet_CloseOperation | Stop a dynamic operation from selecting further targets. |
fleet_CancelOperation | Cancel an operation and its unfinished targets. |
devices_CreateOperation and the related device operation actions run the same
steps on a single device, without stages.
Device Requirements
Nexigon Hub carries out property and wait steps itself. A device fetches command
steps with devices_ClaimOperationWork and reports their results with
devices_ReportOperationStep. Nexigon Agent does so only with operation polling
enabled, and runs a command step only if it provides the command: a custom
command, which requires custom commands to be enabled, or a
built-in command of an
enabled integration.
Commands in Operations
describes the agent’s configuration.