Orchestration
Sensors
React to runs, nodes, checks, source freshness, platform events, or external polls.
A sensor is a Python function under orchestration/sensors/ that SQLBuild calls when an event
happens or on a polling interval. It can trigger jobs, send notifications through a provider, or
both. One module declares one sensor, named after the function (or name="...") and ending in
_sensor.
from sqlbuild.orchestration import RunEvent, RunEventKind, RunRequest, SensorContext, run_event, sensor
@sensor( description="Alert the orders team and rebuild the export when the nightly orders job fails", when=run_event(job="nightly_orders_job", kinds=[RunEventKind.FAILED]),)def orders_failed_sensor(ctx: SensorContext[RunEvent], team_chat): team_chat.post(f"{ctx.event.job} failed: {ctx.event.error} {ctx.event.url or ''}") return RunRequest(job="orders_export_job")Parameters other than ctx inject project providers by
name. Sensors run in the code location (sqb location serve or sqb dev).
Conditions (when)
Section titled “Conditions (when)”when |
Triggered once for | ctx.event type and fields |
|---|---|---|
run_event(job="...", kinds=[...]) |
Each run of the job or group ending in kinds (optional executed_successfully) |
RunEvent: id, occurred_at, job, run_id, status, error, failed_nodes, failed_checks, target, url |
node_event(select="...", kinds=[...]) |
Each success, failure, or recovery of selected nodes in any run | NodeEvent: id, occurred_at, run_id, job, node, event, target, url |
check_event(select="...", kinds=[...]) |
Each check, audit, or SQL test failing or warning inside a job, group, or manual build (not standalone sqb test / sqb audit / sqb scenario test) |
CheckEvent: id, occurred_at, run_id, job, check, status, target, url |
source_new_data(select="...") |
Each new data version of selected sources | SourceNewDataEvent: id, occurred_at, source, data_version, target |
source_stale(select="...", after_seconds=...) |
Each source version older than after_seconds |
SourceStaleEvent: id, occurred_at, source, data_version, after_seconds, target |
platform_event(kinds=[...]) |
Each matching server event (e.g. PlatformEventKind.RUN_FAILED) |
PlatformEvent: id, occurred_at, event, details |
| Omitted | Every minimum_interval_seconds (polling sensor) |
None; store state between polls in ctx.cursor |
kindsuseRunEventKind(SUCCESS,WARN,FAILED,CANCELLED,SKIPPED,BLOCKED,COMPLETED),NodeEventKind,CheckEventKind(FAILED,WARN), andPlatformEventKindfromsqlbuild.orchestration.- A
run_eventon a job also fires when that job finishes inside a job group; arun_eventon the group fires once when the whole group ends. ctx.event.urllinks to the run in the UI (Noneif the server has no sign-in origin).PlatformEventKind.RUN_FAILEDpopulatesctx.event.detailswith the fullrun_failedpayload.
Return values and options
Section titled “Return values and options”| Return value | Tick outcome |
|---|---|
None |
Handled |
SkipReason("...") |
Skipped, with reason |
RunRequest(job="...") or a list of them |
Started, with links to the runs |
Raises or exceeds timeout_seconds |
Failed, with traceback |
RunRequest deduplicates per (job, run_key). Event sensors default run_key to the event ID;
polling sensors must pass run_key explicitly:
from sqlbuild.orchestration import RunRequest, SensorContext, SkipReason, sensor
@sensor(description="Load each new partner order file once", minimum_interval_seconds=300)def partner_files_sensor(ctx: SensorContext[None], partner_files): files = partner_files.list_after(ctx.cursor) if not files: return SkipReason("No new files") ctx.cursor = files[-1].name return [RunRequest(job="partner_orders_job", run_key=file.name) for file in files]| Decorator option | Default | Meaning |
|---|---|---|
minimum_interval_seconds |
30 |
Poll interval, and retry delay after a failed event tick |
timeout_seconds |
60 |
Maximum duration of one tick (up to 600) |
default_status |
running |
paused publishes the sensor disabled |
targets |
All targets | Targets where the sensor runs |
Keep sensor functions short: a code location executes one sensor tick at a time, and long work
belongs in a job started by RunRequest. Literal RunRequest(job="...") names are verified at
compile time.
Failed ticks and skipping events
Section titled “Failed ticks and skipping events”Events are delivered at least once, in order. A failed or timed-out tick leaves its event
undelivered, retries after minimum_interval_seconds, blocks later events behind it, and appears
on the Overview’s attention list until a tick succeeds. Use ctx.event.id to deduplicate side
effects such as chat alerts.
To move past an unhandleable event (requires sensor.reset_cursor on every node of the target):
- Use Skip this event on the stuck tick in the UI, or run
sqb admin change-trigger <TRIGGER_ID> skip-event --event <event-id> --event-id <uuid> --reason "...". - Use Start over (
reset-cursor) to replay every retained event from the start, including skipped ones.
Test a sensor locally
Section titled “Test a sensor locally”Call your local sensor code against a real event from the server or sqb dev without starting runs
or recording ticks:
sqb sensor try orders_failed_sensor --latest --server https://control.example.com --location-id <uuid>See sqb sensor try for all flags and exit codes.