triggers

Event triggers, RunOf, named events, schedr.api.

Generated by make records from the decisions whose topic (or also) is this one; edit the decisions, not this page.

Current

One trigger

  • A trigger runs as a hidden sensor without an attempt (D348): A trigger runs on a watcher slot as a hidden sensor, without a graph node or attempt. Events are acknowledged after storage; the trigger resumes from its bookmark and restarts on code changes.

  • EventNamed waits for events posted through the API (D354): Named events can trigger DAGs or be awaited by nodes, sensors and trigger functions. Waits match events posted since run creation; triggers start at most one run per name and key.

  • A DAG’s trigger has its own row with its switch; no row, no trigger (D459, planned (1.0.0)): Pausing switches a DAG’s trigger off; manual runs start either way. The switch is the trigger’s: dag_triggers holds a row per DAG whose current code has a trigger (its kind, paused, live_since), and no row means none (dags has no paused). A parse gaining a trigger, or changing its kind (Schedule, Run of, Chained, Event, as the UI names them), stores it paused; another trigger of the same kind keeps the switch; losing it deletes the row. Pause and unpause are refused without one. The API’s trigger_state is paused, active or null; dags list’s STATE is paused, active or manual; the UI shows the kind and the switch (active or paused) in one Trigger column, no State column. triggers and trigger_passed are renamed trigger_progress and trigger_progress_passed. Not chosen: the flag on dags (it isn’t the DAG’s); resetting on every trigger change (a cron edit would pause production); a stored manual (a second copy of the code’s fact); a 0002 migration (only rc1’s test databases exist).

@trigger and @trigger.poke

  • Trigger failures, stopping and restarts retain their state (D349): Poke errors retain the bookmark; returned generators stop until code or version changes. Queue limits and idle restarts govern running triggers, whose strikes and consecutive errors persist.

  • @trigger.poke batches events in Python (D352): @trigger.poke(batch=...) gathers a window in Python and stores each item individually. One run receives only its new items as list[Event[T]], keyed by the last new item; no new items means no run. The bookmark advances to the window’s last key, including a repeat. Replaying an individual key produces a singleton batch.

Manual runs, CLI and tests

  • Triggers have endpoints, manual event runs and test helpers (D350): Trigger API and CLI endpoints show, restart and switch on triggers and list events. Manual runs supply an event; test helpers and the DAG page expose trigger events.

Cycles

  • A cycle through trigger=RunOf across DAGs isn’t caught (D394): A cycle of DAGs started by trigger=RunOf(...) isn’t detected (those runs have no parent chain to check); the docs warn about it. TriggerDagOperator’s cycles are caught.

Placement and ordering

  • The trigger loop runs after any write, at a stored moment, or for a posted event (D486): The trigger pass runs in a loop of its own beside the round (decision 485), woken when a write ended in this master outside Database::quietly (a worker’s message, a round’s work, a stream ending; not the lease, the node row, heartbeats, the outbox, retention), when a named event its triggers wait for is posted (Postgres: EVENTS_CHANNEL, announced only when something waits; the post clears those triggers’ stored look), and by the tick’s probe when a trigger’s stored moment (next_fire_at: the earliest of its window’s edges, a restart’s backoff, a generator’s restart_if_idle, written only by the loop) has come or isn’t known; also when a trigger’s state changes in memory (trigger_wake: a call done, a stop’s ack, a slot freed) and at the next tick after a failed pass. A pass first claims the looks not known (claim_looks) and stores a new one only over the value it took, so a post during the pass stays seen. At most one pass every 50 ms, skipped by one EXISTS when no trigger is switched on or running. A pass that wrote wakes the round (option A of 2026-11-14). Not chosen: a wake at each place an input changes (one forgotten leaves a trigger stuck).

  • A waiting wait_for step stores its deadline and what it waits for (D487): A wait_for step the master holds (another DAG’s run, or a named event; no worker, decision 380) is no longer looked at every tick while it waits: before each look it is parked: look_at is its max_wait deadline (the ready check skips it until then), and waits_dag or waits_event name what it waits for. That DAG’s run or task ending (row triggers on state, both backends), that event posted, or its own state changing clears look_at, so the next round’s probe finds it. Not chosen: the deadline alone, re-checked on any write (a busy master would look at every waiting step on every write).

From other topics

  • Repeatedly blocking wait steps and triggers are switched off (D338, wait-steps; built M4.11a3)

  • RunOf waits for or triggers from another DAG’s run (D353, chained-runs; built M4.11d)

  • Tasks call schedr’s REST API through their agent (D356, task-context; built M4.11h)

  • Each tick one probe statement; every check on a stored row or column; triggers and events in a round of their own (D485, assignment; built M5.1f1)

  • @sensor.poke and @trigger.poke accept a plain def (D489, wait-steps; built M5.1o)

Replaced

None.

Where in code

  • crates/schedr-agent/src/agent.rs (D352, D353)

  • crates/schedr-agent/src/attempt.rs (D338)

  • crates/schedr-api/src/named_events.rs::post_event (D354)

  • crates/schedr-api/src/routes.rs (D338, D353)

  • crates/schedr-api/src/routes.rs::restart_trigger (D350)

  • crates/schedr-api/src/views.rs (D338, D353, D354)

  • crates/schedr-api/src/views.rs::TriggerState (D459)

  • crates/schedr-client/src/lib.rs (D354)

  • crates/schedr-config/src/config.rs::switch_off_after (D338)

  • crates/schedr-config/src/loader.rs::RETIRED_TIMINGS (D485)

  • crates/schedr-db/migrations/postgres/0002_next_looks.sql (D487)

  • crates/schedr-db/migrations/sqlite/0002_next_looks.sql (D486)

  • crates/schedr-db/src/commands.rs::EVENTS_CHANNEL (D486)

  • crates/schedr-db/src/dags.rs::NO_FIRE (D485)

  • crates/schedr-db/src/dags.rs::apply_dag_changes (D459)

  • crates/schedr-db/src/dags.rs::scheduled_due (D485)

  • crates/schedr-db/src/database.rs::quietly (D486)

  • crates/schedr-db/src/probe.rs::in_round (D485)

  • crates/schedr-db/src/run_of.rs::park_wait (D487)

  • crates/schedr-db/src/run_of.rs::runs_of (D353)

  • crates/schedr-db/src/triggers.rs::store_batch (D352)

  • crates/schedr-master/src/commands.rs::switch (D459)

  • crates/schedr-master/src/core/triggers.rs::batch_items (D352)

  • crates/schedr-master/src/core/triggers.rs::event_named_pass (D354)

  • crates/schedr-master/src/core/triggers.rs::idle_too_long (D349)

  • crates/schedr-master/src/core/triggers.rs::next_look (D486)

  • crates/schedr-master/src/core/triggers.rs::start_trigger (D348)

  • crates/schedr-master/src/core/triggers.rs::trigger_failed (D349)

  • crates/schedr-master/src/dispatch.rs::count_strike (D338)

  • crates/schedr-master/src/dispatch.rs::wait_for_runs (D487)

  • crates/schedr-master/src/planning.rs::first_waiting (D485)

  • crates/schedr-master/src/quiet.rs::QuietDags (D485)

  • crates/schedr-master/src/scheduler.rs::create_due (D485)

  • crates/schedr-master/src/service.rs::run_triggers (D486)

  • crates/schedr-model/src/trigger.rs::kind (D459)

  • python/schedr/api.py::_script_caller (D356)

  • python/schedr/event_triggers.py::TriggerFunction (D489)

  • python/schedr/run_of.py::RunOf (D353)

  • python/schedr/runner/waiting.py::awaited_poke (D489)

  • python/schedr/runner/watchers.py::_WatcherThreads (D489)

  • python/schedr/script.py::call_api (D356)

  • python/schedr/sensors.py::SensorFunction (D489)

  • python/schedr/testing.py::run_trigger (D350)

Open

  • Q24 (deferred until later): Should a new worker take triggers that are already running?

Details and edge cases, with the reasons; read them before changing this:

  • JOURNAL.md: D394, D459, D486, D487

  • archive/PROJECT.md: Sensors and triggers