Skip to main content

Database

Struct Database 

Source
pub struct Database { /* private fields */ }
Expand description

A connection pool to the schedr database, and the lease its writes are fenced by, if any.

Implementations§

Source§

impl Database

Source

pub async fn ready_instances( &self, now: Timestamp, ) -> Result<Vec<ReadyInstance>, DbError>

Queued task instances of running runs not being cancelled, ready at now: resources’ cleanups first (a cancelled run’s too, decision 277), then oldest ready first.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn assign_attempt( &self, instance_id: &str, worker_id: &str, now: Timestamp, ) -> Result<Option<(String, u32)>, DbError>

Assigns a queued task instance to a worker: it becomes running with a new attempt. Returns the attempt’s ID and try number; None if the instance isn’t queued any more.

§Errors

DbError::Sqlx if a statement fails (nothing is stored then).

Source

pub async fn claim_attempts( &self, claims: &[(&str, &str, &str)], now: Timestamp, ) -> Result<BTreeMap<String, u32>, DbError>

Self::assign_attempt for a round’s whole batch (decision 482): each (instance, worker, attempt) whose instance is still queued becomes running with that new attempt, in two statements over many rows (the claim, then the attempts). Returns the try number of each instance claimed; one no longer queued is left out.

§Errors

DbError::Sqlx if a statement fails (nothing is stored then).

Source

pub async fn start_chained_attempt( &self, instance_id: &str, chained_run_id: &str, now: Timestamp, ) -> Result<Option<(String, u32)>, DbError>

Starts a TriggerDagOperator’s attempt (decisions 361, 380): the queued instance becomes running with a new attempt that no worker runs, started at once, recording the run it starts (chained_run_id) before that run is created. Returns the attempt’s ID and try number; None if the instance isn’t queued any more.

§Errors

DbError::Sqlx if a statement fails (nothing is stored then).

Source

pub async fn chained_attempts(&self) -> Result<Vec<ChainedAttempt>, DbError>

The TriggerDagOperator attempts still open (decision 361), each with the run it started (None while that run isn’t created yet: a master stopped in between) and its parent run’s state.

§Errors

DbError if the query fails or a row doesn’t read.

Source

pub async fn undo_assignment( &self, attempt_id: &str, state: TaskInstanceState, ready_at: Option<Timestamp>, reason: Option<&str>, now: Timestamp, ) -> Result<(), DbError>

Takes back an assignment the worker rejected: the attempt is deleted (a rejection is not a try), the try number goes back, and the instance gets state (queued, ready at ready_at, or unschedulable) with reason to show.

§Errors

DbError::Sqlx if a statement fails (nothing is stored then).

Source

pub async fn first_start( &self, instance_id: &str, ) -> Result<Option<Timestamp>, DbError>

An attempt by ID.

§Errors

DbError if the query fails or stored data doesn’t read. When an instance’s first attempt started: a wait step’s max_wait runs from then (decision 321).

§Errors

DbError if the statement fails or a time doesn’t read.

Source

pub async fn first_starts( &self, instance_ids: &[&str], ) -> Result<BTreeMap<String, Timestamp>, DbError>

Self::first_start of each of instance_ids at once (a round’s ready wait steps, decision 482): the instances never started are absent.

§Errors

DbError if a statement fails or a time doesn’t read.

Source

pub async fn attempt( &self, attempt_id: &str, ) -> Result<Option<StoredAttempt>, DbError>

An attempt by its ID.

§Errors

DbError if the statement fails or a row doesn’t read.

Source

pub async fn open_attempts( &self, worker_id: Option<&str>, ) -> Result<Vec<StoredAttempt>, DbError>

Attempts still running (no end recorded), of one worker or of every worker.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn mark_replaced( &self, attempt_ids: &[String], now: Timestamp, ) -> Result<(), DbError>

Marks open attempts as left behind by a replaced incarnation (decision 443): they end lost once its lease is over. A mark already made stands.

§Errors

DbError if a write fails.

Source

pub async fn clear_replaced( &self, attempt_ids: &[String], ) -> Result<(), DbError>

Clears the marks of Self::mark_replaced: the hold did its work (ended or moved the attempt), or a worker’s journal reports it, alive (Grok’s review of decision 443).

§Errors

DbError if a write fails.

Source

pub async fn replaced_attempts(&self) -> Result<Vec<String>, DbError>

The open attempts a replaced incarnation left behind (Self::mark_replaced).

§Errors

DbError if the query fails.

Source

pub async fn set_task_result( &self, attempt_id: &str, result: &[u8], ) -> Result<(), DbError>

Keeps the task’s result of an open attempt while its cleanup runs (decision 229).

§Errors

DbError if the write fails.

Source

pub async fn task_result( &self, attempt_id: &str, ) -> Result<Option<Vec<u8>>, DbError>

The task’s result kept for an attempt, if its process’s end was reported.

§Errors

DbError if the query fails.

Source

pub async fn add_cleanup_handles( &self, attempt_id: &str, first: u32, handles: &[String], limit: usize, ) -> Result<bool, DbError>

Adds handles an attempt registered, from place first on, keeping what is there (they are sent again after a reconnect), up to limit bytes in all. Returns whether all fitted.

§Errors

DbError if a statement fails.

Source

pub async fn cleanup_handles_unbroken( &self, attempt_id: &str, ) -> Result<u32, DbError>

How many of an attempt’s handles the master has from the first on without a gap: a worker holding more cleans those after them (B169). One stored past a gap is cleaned there again rather than one in the gap left behind (Codex’s review of B169).

§Errors

DbError if the query fails.

Source

pub async fn cleanup_handles( &self, attempt_id: &str, ) -> Result<Vec<String>, DbError>

An attempt’s handles, each as JSON text, in registration order.

§Errors

DbError if the query fails.

Source

pub async fn move_cleanup( &self, attempt_id: &str, result: &[u8], not_before: Timestamp, ) -> Result<(), DbError>

Takes an attempt’s cleanup off its worker, to wait for another (decision 243), with the task’s result if none is kept yet, counting a move (decision 247).

§Errors

DbError if the write fails.

Source

pub async fn take_back_cleanup( &self, attempt_id: &str, worker_id: &str, drop_result: bool, ) -> Result<bool, DbError>

Gives a cleanup waiting to move back to the worker it moved from, which came back holding handles the master never got (B169): the move is undone, and with drop_result the task’s result the move kept goes too (the worker reports its own). false if it no longer waits for a worker, or moved from another.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn rest_owed_by( &self, attempt_id: &str, ) -> Result<Option<String>, DbError>

The worker an attempt’s cleanup first moved from (the one that ran its task), while no rest of its cleanup was added (B169): handles it registered that the master never got are cleaned there. Moves after the first don’t change it (Codex’s review of B169).

§Errors

DbError if the read fails.

Source

pub async fn cleanup_moved_from( &self, attempt_id: &str, ) -> Result<Option<String>, DbError>

The worker an open attempt’s cleanup moved from, while it waits for another (no worker yet): that worker’s late result still counts (decision 282).

§Errors

DbError if the read fails.

Source

pub async fn assign_cleanup( &self, attempt_id: &str, worker_id: &str, now: Timestamp, ) -> Result<bool, DbError>

Gives a moved cleanup to worker_id, if it still waits. Returns whether it did.

§Errors

DbError if the write fails.

Source

pub async fn unassign_cleanup(&self, attempt_id: &str) -> Result<(), DbError>

Takes back a moved cleanup its worker refused or never started: it waits again, no move counted.

§Errors

DbError if the write fails.

Source

pub async fn unstarted_cleanups( &self, cutoff: Timestamp, except_workers: &[String], limit: u32, ) -> Result<Vec<StoredAttempt>, DbError>

The moved cleanups assigned before cutoff and not started, but those of except_workers.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn waiting_cleanups( &self, now: Timestamp, ) -> Result<Vec<(String, ReadyInstance)>, DbError>

The moved cleanups waiting for a worker, oldest first: each attempt’s ID, and what an assignment needs.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn active_attempts(&self) -> Result<Vec<ActiveAttempt>, DbError>

Every open attempt (no end recorded) with its DAG, run and task: what the concurrency limits count (decision 88A), read when the master starts dispatching.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn active_counts( &self, dag_id: &DagId, ) -> Result<Vec<(String, TaskId, u32)>, DbError>

The open attempts of dag_id’s runs, counted by run and task: (run, task, count) (the DAG page’s limits with their counts, decision 96).

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn unstarted_attempts( &self, cutoff: Timestamp, except_workers: &[String], limit: u32, ) -> Result<Vec<StoredAttempt>, DbError>

The oldest limit attempts assigned before cutoff that never reported Started, but those of except_workers (workers that may come back: left out before the limit, so they can’t fill it, F14’s review), oldest assigned first (a backlog read a round’s worth at a time, B52).

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn mark_started( &self, attempt_id: &str, start_method: &str, at: Timestamp, ) -> Result<bool, DbError>

Records Started for a running attempt, started at (the worker’s start in master time, M5.1m, never before its assignment; a start already recorded is kept). Returns whether it is still running.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn mark_started_many( &self, starts: &[(&str, Timestamp)], start_method: &str, ) -> Result<BTreeSet<String>, DbError>

Records Started for several running attempts started by start_method, each at its own time, as Self::mark_started does each, in one statement (M5.1d, M5.1m). Returns the IDs still running.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn mark_adopted( &self, attempt_id: &str, now: Timestamp, ) -> Result<(), DbError>

Records that a running attempt has started, with no start method: its worker reconnected with it in its journal, its Started perhaps lost (B50). A start already recorded is kept.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn attempts_by_ids( &self, ids: &[&str], ) -> Result<Vec<StoredAttempt>, DbError>

Several attempts by ID (M4B.4: a turn’s Finisheds read in one query); those that don’t exist are left out.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn end_attempts( &self, ends: &[(&str, &AttemptEnd)], now: Timestamp, ) -> Result<BTreeSet<String>, DbError>

Records how several attempts ended, as Self::end_attempt does each, in statements of up to ENDS_PER_STATEMENT (M4B.4, B184). Returns the IDs whose end this call recorded (not those ended already). Each ID at most once.

§Errors

DbError::Sqlx if a statement fails.

Source

pub async fn end_attempt( &self, attempt_id: &str, end: &AttemptEnd, now: Timestamp, ) -> Result<bool, DbError>

Records how an attempt ended, unless an end is already recorded. Returns whether this call recorded it. A rest cleanup added before (B169, Self::add_rest_cleanup) is kept: the two cleanups’ results combine as there.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn add_rest_cleanup( &self, attempt_id: &str, rest: &CleanupEnd, ) -> Result<bool, DbError>

Adds the cleanup of the handles a moved cleanup didn’t have (B169: registered while the master couldn’t hear the worker, which ran it on its return) to the attempt’s: a failure of either (failed, worker_lost) is the result, else either’s ok; tries and time add up, the rest’s error is kept. Before the attempt ends, its end combines with it. Once only: false if a rest was added already.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn run_outputs( &self, run_id: &str, ) -> Result<BTreeMap<TaskId, Value>, DbError>

The outputs stored for a run’s tasks, by task ID (what downstream tasks get as inputs).

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn upstream_outcomes( &self, run_id: &str, tasks: &[&TaskId], ) -> Result<BTreeMap<TaskId, Option<String>>, DbError>

What tasks of a run ended with, for a task that uses them: by task ID, the outcome of one that succeeded, None for one that was skipped (each of its edges counts as not taken). Tasks in any other state are left out.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn outputs_of( &self, run_id: &str, tasks: &[&TaskId], ) -> Result<BTreeMap<TaskId, Value>, DbError>

The outputs stored for tasks of a run, by task ID: what one task gets as inputs, without reading every other task’s (a wide DAG’s assignment read the whole run’s, B18).

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn ended_in_order( &self, run_id: &str, tasks: &[&TaskId], ) -> Result<Vec<TaskId>, DbError>

tasks of a run whose success is stored, in the order they ended (ended_at: each row of one write a microsecond apart, in its order; a later cleanup result moves only updated_at). Those succeeding now aren’t among them yet: they ended last.

§Errors

DbError if the query fails or a stored ID doesn’t read.

Source

pub async fn instance_results( &self, run_id: &str, task: &TaskId, ) -> Result<Vec<InstanceResult>, DbError>

A mapped task’s instances in a run, in map_index order: each one’s state, and its outcome and output once it succeeded (what a mapped task’s whole output and its lanes are made of, decisions 70 and 77).

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn instance_result( &self, run_id: &str, task: &TaskId, map_index: i32, ) -> Result<Option<InstanceResult>, DbError>

One instance of a mapped task in a run: its state, and its outcome and output once it succeeded (what a lane gives its downstream instance).

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn unschedulable_instances( &self, ) -> Result<Vec<Unschedulable>, DbError>

The unschedulable task instances of running runs: each one’s run, task, map_index, DAG version and since when it waits (decision 273).

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn requeue_unschedulable( &self, now: Timestamp, ) -> Result<u64, DbError>

Queues every unschedulable task instance again (the set of workers changed). Returns how many.

§Errors

DbError::Sqlx if the statement fails.

Source§

impl Database

Source

pub async fn insert_backfill( &self, backfill: &NewBackfill<'_>, ) -> Result<bool, DbError>

Stores a backfill; false if one with its ID is there already (a command applied again).

§Errors

DbError::Sqlx if the write fails.

Source

pub async fn covered_times( &self, dag_id: &DagId, from: Timestamp, to: Timestamp, ) -> Result<BTreeSet<Timestamp>, DbError>

The planned_fors in [from, to] of the DAG’s runs that succeeded or haven’t finished: the fire times a backfill skips without --all (decision 400).

§Errors

DbError if the query fails or a stored time doesn’t read.

Source

pub async fn succeeded_times( &self, dag_id: &DagId, from: Timestamp, to: Timestamp, ) -> Result<BTreeSet<Timestamp>, DbError>

As Self::covered_times, by successful runs only: the fire times no scheduled run will take any more (decision 485).

§Errors

DbError if the query fails or a stored time doesn’t read.

Source

pub async fn backfill( &self, id: &str, ) -> Result<Option<BackfillRecord>, DbError>

A backfill, with its runs counted by state; None for an unknown ID.

§Errors

DbError if a query fails or stored data doesn’t read.

Source

pub async fn dag_backfills( &self, dag_id: &DagId, limit: u32, ) -> Result<Vec<BackfillRecord>, DbError>

The DAG’s backfills, newest first, at most limit.

§Errors

DbError if a query fails or stored data doesn’t read.

Source

pub async fn unfinished_backfill_runs( &self, id: &str, ) -> Result<Vec<String>, DbError>

The backfill’s runs that haven’t finished, oldest first: what cancelling it cancels (decision 402).

§Errors

DbError::Sqlx if the query fails.

Source§

impl Database

Source

pub async fn changes(&self, poll: Duration) -> Result<Option<Changes>, DbError>

The changes from now on; None when they can’t be followed (Postgres with notifications off, or behind a connection pooler in transaction mode without a notifications_url): the UI then refreshes on a timer.

§Errors

DbError if the database can’t be reached or checked.

Source

pub async fn changes_reading( &self, poll: Duration, rows: usize, ) -> Result<Option<Changes>, DbError>

As Self::changes, SQLite’s polls reading at most rows rows each (SCHEDR_HIDDEN__DATABASE__CHANGES_POLL_ROWS).

§Errors

As Self::changes.

Source§

impl Database

Source

pub async fn change_notifications(&self) -> Result<bool, DbError>

Whether the writes announce their changes (the change triggers are on): on Postgres all of them enabled, on SQLite the changes_switch row.

§Errors

DbError if the query fails.

Source

pub async fn set_change_notifications(&self, on: bool) -> Result<bool, DbError>

Turns the change triggers on or off ([database] change_notifications), only if they aren’t so already; whether anything changed. On Postgres it alters the tables (a brief exclusive lock on each): schedr db migrate and --migrate call it, holding the master’s lease, never a running master.

§Errors

DbError if a statement fails.

Source§

impl Database

Source

pub async fn insert_command( &self, command: &Command, requested_by: &str, now: Timestamp, ) -> Result<String, DbError>

Writes a command for the master; returns its ID.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn submit_command( &self, command: &Command, requested_by: &str, key: Option<&str>, now: Timestamp, ) -> Result<Submitted, DbError>

Writes a command for the master, once per key (the client’s Idempotency-Key, B140): a request sent again after its answer was lost finds the command it stored, as long as the same person sends the same command with it.

§Errors

DbError if a statement fails or the stored command doesn’t read.

Source

pub async fn command_notifications( &self, ) -> Result<Option<CommandNotifications>, DbError>

Listens for new commands: notifications on Postgres, through notifications_url if set, else this database’s own connections; None (the master polls) on SQLite, which has none, with notifications off, or when the connection it would listen through passes a pooler in transaction mode: there a LISTEN holds on to a server connection that the pooler lends to other clients, whose queries then fail on notifications they don’t expect (B16). That is checked first (listening_is_safe); found, it says so and how to have notifications all the same.

§Errors

DbError::Sqlx if the listening connection can’t be opened or checked.

Source

pub async fn pending_commands( &self, limit: u32, ) -> Result<Vec<PendingCommand>, DbError>

The oldest limit pending commands, oldest first: a backlog is read a round’s worth at a time, not whole each round (B52).

§Errors

DbError::Sqlx if the query fails.

Source

pub async fn mark_applying( &self, id: &str, now: Timestamp, ) -> Result<(), DbError>

Marks a pending command as being applied, before its first write: if its round fails before it is decided, the next one knows it may find its own work done (B7).

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn decide_command( &self, id: &str, status: CommandStatus, reason: Option<&str>, result: Option<&Value>, now: Timestamp, ) -> Result<bool, DbError>

Decides a pending command: applied with its result, or rejected with a reason. Returns whether it was still pending.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn set_command_result( &self, id: &str, result: &Value, ) -> Result<bool, DbError>

Replaces an applied command’s result: a connections command’s, as its workers answer (the master the only writer, one answer at a time). Whether it was applied.

§Errors

DbError if the update fails.

Source

pub async fn command(&self, id: &str) -> Result<Option<CommandRecord>, DbError>

A command row by ID.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn run_commands( &self, run_id: &str, ) -> Result<Vec<CommandRecord>, DbError>

The commands about a run, oldest first: those naming it (cancel it, cancel or retry one of its tasks), the trigger that made it (its result names it) and a pause that cancelled it (its result lists it). run_id as schedr writes IDs (lowercase).

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn connections_commands_lost( &self, why: &str, ) -> Result<usize, DbError>

Marks every job still running in a connections command’s result lost, with why: at a master’s start, the answers to an earlier master’s jobs never come. How many commands it changed.

§Errors

DbError if a query fails or stored data doesn’t read.

Source§

impl Database

Source

pub async fn record_root_hash( &self, root: &str, content_hash: &str, switched: bool, now: Timestamp, ) -> Result<(), DbError>

Records that a worker reported root at hash: a switch (the worker had another hash before) makes it the most recent; a first report only records it if unknown.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn root_hash_switches( &self, root: &str, ) -> Result<BTreeMap<String, Timestamp>, DbError>

When workers last switched to each recorded hash of root.

§Errors

DbError if the query fails or a stored time doesn’t read.

Source

pub async fn parses_of( &self, root: &str, content_hash: &str, ) -> Result<Vec<StoredParse>, DbError>

Every stored parse of (root, hash), one per schedr version, oldest first.

§Errors

DbError if the query fails or a stored time doesn’t read.

Source

pub async fn find_parse( &self, root: &str, content_hash: &str, schedr_version: &str, ) -> Result<Option<String>, DbError>

The ID of the parse of (root, hash, schedr version), if stored.

§Errors

DbError::Sqlx if the query fails.

Source

pub async fn insert_parse( &self, parse: &NewParse<'_>, ) -> Result<String, DbError>

Stores a parse result and its files, and returns its ID. A parse of the same (root, hash, schedr version) stored meanwhile wins: its ID is returned and nothing is stored.

§Errors

DbError::Sqlx if a statement fails (nothing is stored then).

Source

pub async fn replace_parse_files( &self, parse_id: &str, files: &[ParsedFile], worker_id: &str, parsed_at: Timestamp, ) -> Result<(), DbError>

Replaces files of a stored parse (a re-parse of files that failed transiently, decision 72.2): each of files takes the place of the stored file at its path, parsed by worker_id at parsed_at (decision 93).

§Errors

DbError::Sqlx if a statement fails.

Source

pub async fn parse_file_workers( &self, parse_id: &str, ) -> Result<BTreeMap<String, String>, DbError>

The worker that parsed each file of a parse, by path (decision 93): the parse’s own, or the one that parsed the file again.

§Errors

DbError::Sqlx if the query fails.

Source

pub async fn parse_files( &self, parse_id: &str, ) -> Result<Vec<ParsedFile>, DbError>

The files of a stored parse, in path order.

§Errors

DbError::Sqlx if the query fails, DbError::InvalidData if a stored file doesn’t read back.

Source

pub async fn current_connections(&self, root: &str) -> Result<Registry, DbError>

The connections of root’s current parse (decision 174), as the master builds its registry: empty when it has none.

§Errors

DbError::Sqlx if the query fails, DbError::InvalidData if a stored connection doesn’t read back.

Source

pub async fn set_current_parse( &self, root: &str, parse_id: &str, now: Timestamp, ) -> Result<(), DbError>

Records parse_id as root’s current parse (the master’s decision), at now.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn current_parses(&self) -> Result<BTreeMap<String, String>, DbError>

Each root’s current parse, as last recorded by Self::set_current_parse: root to parse ID.

§Errors

DbError::Sqlx if the query fails.

Source

pub async fn current_import_errors( &self, ) -> Result<Vec<ImportErrorRecord>, DbError>

The files of each root’s current parse that failed to import, by root and path (decision 66).

§Errors

DbError::Sqlx if the query fails, DbError::InvalidData if a stored error or time doesn’t read back.

Source

pub async fn stored_dags(&self) -> Result<Vec<StoredDag>, DbError>

Every stored DAG (removed ones too), with its current version, in DAG ID order.

§Errors

DbError::Sqlx if the query fails, DbError::InvalidData if stored JSON doesn’t read back.

Source

pub async fn held_dags(&self) -> Result<BTreeMap<String, bool>, DbError>

The DAGs whose queued tasks mustn’t be assigned, each true when removed (their tasks not started are cancelled, B192) and false when in an ID conflict (they wait until it is resolved, B193; decision 107).

§Errors

DbError::Sqlx if the query fails.

Source

pub async fn removed_dags_runs(&self) -> Result<Vec<String>, DbError>

The unfinished runs of removed DAGs with something not started yet (B192): queued runs, and running ones with a task scheduled, queued, up for retry or unschedulable, or with an assignment not started whose cancel isn’t asked yet. The master cancels what they haven’t started; their running attempts finish.

§Errors

DbError::Sqlx if the query fails.

Source

pub async fn scheduled_due( &self, now: Timestamp, ) -> Result<Vec<(DagId, Option<Timestamp>)>, DbError>

The scheduled DAGs that can run whose next fire time has come at now or isn’t known (decision 485), with what is stored (None: not known).

§Errors

DbError if the query fails or a stored time doesn’t read.

Source

pub async fn next_fires( &self, ) -> Result<HashMap<DagId, Option<Timestamp>>, DbError>

Every trigger’s stored next time (None: not known): a scheduled DAG’s next fire time, for a round visiting every DAG (decision 485), and an event trigger’s next moment, for the trigger loop (decision 486).

§Errors

DbError if the query fails or a stored time doesn’t read.

Source

pub async fn claim_looks( &self, ) -> Result<HashMap<DagId, Option<Timestamp>>, DbError>

The trigger loop’s looks, taken at the start of its pass (decision 486): each trigger it looks after whose look isn’t known (NULL: a named event posted, a new version, an unpause) is set to NO_FIRE first, then all are read. A post from then on finds a look to clear, and is announced; one before it is in the pass’s scans (Grok’s second review of M5.1f2: a post while the look was already NULL cleared nothing, and the pass’s store hid it). The pass looks at every trigger anyway; the look only wakes it.

§Errors

DbError if a statement fails or a stored time doesn’t read.

Source

pub async fn set_next_fire_if( &self, dag_id: &DagId, was: Timestamp, at: Timestamp, ) -> Result<bool, DbError>

As Self::set_next_fire, only while the stored time is still was: a time cleared meanwhile (a named event posted during the trigger pass, Grok’s review of M5.1f2) is left cleared, for the probe to find. A look not known is never stored over: whatever cleared it is looked at by the next pass. Returns whether it was stored.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn set_next_fire( &self, dag_id: &DagId, at: Timestamp, ) -> Result<(), DbError>

Stores when the master looks at dag_id’s trigger next (NO_FIRE: nothing ahead): a scheduled DAG’s next fire time (decision 485), an event trigger’s next moment (decision 486). A DAG without a trigger’s row changes nothing.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn stored_dag( &self, dag_id: &DagId, ) -> Result<Option<StoredDag>, DbError>

DAG dag_id as Self::stored_dags lists it, read alone (B136: one DAG’s reads read every DAG); None if it was never stored.

§Errors

DbError if the query fails or its stored DAG doesn’t read.

Source

pub async fn set_paused( &self, dag_id: &DagId, paused: bool, ) -> Result<bool, DbError>

Pauses or unpauses a DAG’s trigger. Returns whether it has one (decision 459: a DAG run only by hand has no switch).

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn set_paused_at( &self, dag_id: &DagId, paused: bool, now: Timestamp, ) -> Result<bool, DbError>

As Self::set_paused, unpausing at now: its live_since (decision 353) changes in the same statement, cleared by a pause, set by an unpause unless it was live already.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn apply_dag_changes( &self, changes: &[DagChange], now: Timestamp, ) -> Result<(), DbError>

Stores changes to the DAG list, all or none.

§Errors

DbError::Sqlx if a statement fails (nothing is stored then).

Source§

impl Database

Source

pub async fn connect(url: &str) -> Result<Self, DbError>

Connects to the database a URL names. SQLite files are created if missing, and foreign keys are enforced. An in-memory SQLite database (sqlite::memory:) uses a single connection, since each connection would otherwise see its own empty database.

§Errors

Returns DbError::UnsupportedUrl for an unknown scheme, or DbError::Sqlx if the URL is malformed or the connection fails.

Source

pub async fn connect_with_timeout( url: &str, query_timeout: Duration, ) -> Result<Self, DbError>

Connects to the database at url, no query (or wait for a connection) taking longer than query_timeout, enforced here around each query (DbError::QueryTimeout; a server-side statement_timeout, set by the DBA, stops the work in Postgres too), and SQLite’s busy timeout. The roles use it; migrations don’t (a long migration must finish). It works through any connection pooler: nothing is set on the session.

§Errors

As Self::connect.

Source

pub const fn pool(&self) -> &Pool

The connection pool.

Source

pub fn fenced_as(&self) -> Option<&str>

The lease holder this database is fenced for (a master’s ID): None if it isn’t.

Source

pub fn fenced(&self, holder: &str, epoch: i64) -> Self

This database for the master holding the lease as holder with takeover counter epoch: each of its writes checks, in its own transaction, that the lease is still that, and is refused (DbError::NotLeading) once another master took it over. On Postgres the check holds the lease’s row until the write commits, so a takeover waits for it; SQLite runs one write at a time anyway. A write sent before a takeover but reaching the database after it (held up by the network or a pooler’s queue) is refused too: what the master’s own clock can’t rule out (see archive/PROJECT.md, production path).

Source

pub async fn dag_version(&self, version_id: &str) -> Result<Arc<Dag>, DbError>

The DAG of version version_id, from the cache or read and parsed once (B13).

§Errors

DbError if the query fails or the stored DAG doesn’t read; DbError::InvalidData for an unknown version.

Source

pub fn with_notifications(self, on: bool, url: Option<String>) -> Self

This database with notifications of new commands on or off ([database] notifications), the master listening through url if given (notifications_url) or through this database’s own connections. Off: commands aren’t announced, and the master polls (see Database::command_notifications).

Source

pub fn with_dag_versions_cached(self, most: usize) -> Self

This database keeping at most most DAG versions parsed (decision 493), a cache of its own (made before its clones).

Source

pub async fn changed(&self)

Waits until a write transaction ended outside Database::quietly since the last wait returned (writes in between are one wake): the master’s trigger loop (decision 486).

Source

pub async fn waits_due(&self)

Waits until a named event posted in this process cleared waiting steps’ looks since the last wait returned (decision 487): the master’s round looks at them at once.

Source

pub async fn quietly<F: Future>(&self, work: F) -> F::Output

Runs work with its writes left out of Database::changed: housekeeping that changes nothing a trigger depends on (the lease, the master’s row, a worker’s last heartbeat), and the trigger loop’s own writes.

Source

pub fn writes_ended(&self) -> u64

Write transactions ended so far, in this process (shared by clones).

Source

pub fn query_timeout(&self) -> Duration

The longest a query may take: the pool’s wait for a connection, which Self::connect_with_timeout sets to the query limit (sqlx’s 30 s default otherwise).

Source

pub const fn backend(&self) -> Backend

The backend of this database.

Source

pub async fn migrate(&self) -> Result<(), DbError>

Applies the migrations not applied yet (what schedr db migrate does).

§Errors

Returns DbError::Migrate if a migration fails or the applied migrations don’t match the built-in ones.

Source

pub async fn migrate_as_lease_holder(&self) -> Result<(), DbError>

As Self::migrate, without the migrator’s own lock (a session advisory lock on Postgres, which connection poolers in transaction mode don’t keep): for a master holding the lease, which already rules out a second one migrating (see crate::lease).

§Errors

As Self::migrate.

Source

pub async fn applied_migrations(&self) -> Result<Vec<i64>, DbError>

The versions of the migrations applied successfully, in order; empty if none.

§Errors

Returns DbError::Sqlx if the query fails.

Source

pub async fn schema_status(&self) -> Result<SchemaStatus, DbError>

How the database’s schema compares with this binary’s migrations.

§Errors

Returns DbError::Sqlx if reading the applied migrations fails.

Source§

impl Database

Source

pub async fn newly_running(&self) -> Result<Vec<NewlyRunning>, DbError>

Running runs with no task instances yet, oldest first.

§Errors

DbError if the query fails or a stored DAG doesn’t read.

Source

pub async fn create_instances( &self, run_id: &str, states: &[(TaskId, i32, TaskInstanceState)], now: Timestamp, ) -> Result<(), DbError>

Creates task instances of a run in their first states: (task, map_index, state); a run’s own when it starts, a mapped task’s when it expands.

§Errors

DbError::Sqlx if a statement fails (nothing is stored then).

Source

pub async fn run_tasks(&self, run_id: &str) -> Result<Option<RunTasks>, DbError>

A run with its DAG version and task instances; None for an unknown run.

§Errors

DbError if a query fails or stored data doesn’t read.

Source

pub async fn set_cleanup_result( &self, instance_id: &str, result: CleanupResult, now: Timestamp, ) -> Result<(), DbError>

Records how a cleanup of an instance ended. A failure stays: a later attempt’s cleanup succeeding doesn’t undo it (it fails the run, see archive/PROJECT.md, Run result).

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn update_instances( &self, run_id: &str, updates: &[InstanceUpdate], now: Timestamp, ) -> Result<(), DbError>

Stores changes to a run’s task instances, all or none.

§Errors

DbError::Sqlx if a statement fails.

Source

pub async fn set_queued_reasons( &self, reasons: &[(String, String)], now: Timestamp, ) -> Result<(), DbError>

Sets the waiting reasons of queued task instances ((instance ID, reason)): one statement per distinct reason and 500 instances, where it was one per instance (B18); most waiting tasks share a few reasons.

§Errors

DbError::Sqlx if a statement fails.

Source

pub async fn finish_run( &self, run_id: &str, state: RunState, now: Timestamp, ) -> Result<(), DbError>

Records a run’s result.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn request_cancel( &self, run_id: &str, now: Timestamp, ) -> Result<(), DbError>

Marks a run as being cancelled (the first request counts).

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn request_task_cancel( &self, run_id: &str, task_id: &TaskId, now: Timestamp, ) -> Result<(), DbError>

Marks a running task as being cancelled (the first request counts).

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn map_sizes( &self, run_id: &str, task_id: &TaskId, ) -> Result<Option<Vec<usize>>, DbError>

A mapped task’s dimensions’ sizes in a run, once it expanded.

§Errors

DbError if the query fails or the stored sizes don’t read.

Source

pub async fn request_instance_cancel( &self, run_id: &str, task_id: &TaskId, map_index: i32, now: Timestamp, ) -> Result<(), DbError>

Marks one running task instance as being cancelled (a mapped task’s step that failed, decision 75a), the first request counting.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn retry_unschedulable( &self, run_id: &str, __arg2: (&TaskId, Option<i32>), now: Timestamp, ) -> Result<bool, DbError>

Queues an unschedulable task again (schedr tasks retry); whether it was one.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn due_retries( &self, now: Timestamp, ) -> Result<Vec<(String, TaskId, i32)>, DbError>

The task instances whose retry delay has passed: (run ID, task ID, map_index), oldest first.

§Errors

DbError if the query fails or a stored ID doesn’t read.

Source

pub async fn store_output( &self, instance_id: &str, outcome: &str, value: &Value, ) -> Result<(), DbError>

Stores a task instance’s output (stored JSON) with its outcome.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn store_outputs( &self, outputs: &[(&str, &str, &Value)], ) -> Result<(), DbError>

Stores several instances’ outputs, as Self::store_output does each, in statements of up to UPDATES_PER_STATEMENT rows (M4B.4, B184). An instance named twice keeps the later.

§Errors

DbError::Sqlx if a statement fails.

Source

pub async fn store_task_output( &self, run_id: &str, task_id: &TaskId, outcome: &str, value: &Value, ) -> Result<(), DbError>

Stores the output of a task that isn’t mapped, by its ID in the run (a task the master ended itself: no attempt knows its instance).

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn output( &self, instance_id: &str, ) -> Result<Option<(String, Value)>, DbError>

A task instance’s output and outcome, if stored.

§Errors

DbError if the query fails or the stored value doesn’t read.

Source§

impl Database

Source

pub async fn create_lease_table(&self) -> Result<(), DbError>

Creates the lease’s table if it isn’t there (before the migrations, which create it too; a race between two masters creating it is an error the caller tries again).

§Errors

DbError::Sqlx if the statement fails, DbError::QueryTimeout past the limit.

Source

pub async fn take_lease( &self, holder: &str, period: Duration, ) -> Result<Option<i64>, DbError>

Takes the lease for holder (a master’s incarnation) until period from now by the database’s clock: the takeover counter if holder holds it now, None if another master does and its lease hasn’t expired. On Postgres a takeover waits for the writes of the master before it that are in progress.

§Errors

DbError::Sqlx if the statement fails, DbError::QueryTimeout past the limit.

Source

pub async fn renew_lease( &self, holder: &str, epoch: i64, period: Duration, ) -> Result<bool, DbError>

Renews holder’s lease taken at takeover counter epoch until period from now by the database’s clock: false if it is no longer holder’s at epoch (another master took it over; it is left as it is).

§Errors

DbError::Sqlx if the statement fails, DbError::QueryTimeout past the limit.

Source

pub async fn lease_holder(&self) -> Result<Option<String>, DbError>

The master holding the lease now, by the database’s clock: None if none does (no master took it, or its lease expired).

§Errors

DbError::Sqlx if the statement fails, DbError::QueryTimeout past the limit.

Source

pub async fn lease_held(&self) -> Result<Option<(String, String)>, DbError>

The master holding the lease now and when its lease runs out (UTC, as stored), by the database’s clock: None if none does (decision 452: a master that isn’t leading names the leader to its workers).

§Errors

DbError::Sqlx if the statement fails, DbError::QueryTimeout past the limit.

Source

pub async fn release_lease(&self, holder: &str) -> Result<(), DbError>

Gives the lease up if holder has it (a clean shutdown), so a standby takes over at once instead of when it expires.

§Errors

DbError::Sqlx if the statement fails, DbError::QueryTimeout past the limit.

Source§

impl Database

Source

pub async fn post_named_event( &self, event: &NewNamedEvent<'_>, posted_by: &str, request_key: Option<&str>, now: Timestamp, ) -> Result<Posted, DbError>

Posts event for posted_by at now, once per request_key (the client’s Idempotency-Key): sent again after its answer was lost, it finds the event it stored, as long as the same person sends the same event.

§Errors

DbError if a statement fails or the stored event doesn’t read.

Source

pub async fn named_events_unseen( &self, name: &str, dag_id: &str, since: Timestamp, limit: u32, ) -> Result<Vec<NamedEvent>, DbError>

The events named name posted from since on whose key dag_id’s events don’t have, oldest first, at most limit: what an EventNamed trigger starts runs for (decision 354). Read by the keys a DAG has, not strictly after the last one seen, so one stored late (its time taken before its commit) is still found; since bounds the look back.

§Errors

DbError if the query fails or a row doesn’t read.

Source

pub async fn named_event_unpassed( &self, name: &str, dag_id: &str, since: Timestamp, ) -> Result<Option<NamedEvent>, DbError>

The first event named name posted from since on that dag_id’s @trigger(wait_for= EventNamed(...)) hasn’t passed (decision 354): read by what it passed, not strictly after the last one, so one stored late is still called for, once.

§Errors

DbError if the query fails or the row doesn’t read.

Source

pub async fn forget_passed_before( &self, dag_id: &str, name: &str, before: Timestamp, ) -> Result<u64, DbError>

Forgets what dag_id’s trigger passed of the events named name posted before before: read back only from a lookback behind its last (B186). Gives how many.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn passed_floor( &self, dag_id: &str, ) -> Result<Option<Timestamp>, DbError>

Below what dag_id’s trigger no longer reads events: what it passed there is forgotten.

§Errors

DbError if the query fails or the time doesn’t read.

Source

pub async fn first_named_event( &self, name: &str, key: Option<&str>, since: Timestamp, after: Option<(Timestamp, &str)>, ) -> Result<Option<NamedEvent>, DbError>

The first event named name with key (any, if None) posted from since on, and strictly after after (a (posted_at, id) cursor: one a sensor’s function said NOT_YET to) when given: what a step waiting in a run started at since gets (decision 354: one posted before the step began waiting, but after its run started, counts).

§Errors

DbError if the query fails or the row doesn’t read.

Source

pub async fn next_named_event_for( &self, __arg1: (&str, Option<&str>), since: Timestamp, after: Timestamp, __arg4: (SignedDuration, &str), ) -> Result<Option<NamedEvent>, DbError>

The first event of name (and key) posted since since that the sensor of instance_id wasn’t handed and said NOT_YET to, posted no earlier than back before its cursor after (B185): one committed late, its time taken before its commit, sits behind the cursor, and is found still within that lookback.

§Errors

DbError if the query fails or the row doesn’t read.

Source

pub async fn named_events_by_id( &self, id: &str, ) -> Result<Option<NamedEvent>, DbError>

One event, by its ID.

§Errors

DbError if the query fails or the row doesn’t read.

Source

pub async fn named_events( &self, name: Option<&str>, limit: u32, ) -> Result<Vec<NamedEvent>, DbError>

The newest events, of name if given, at most limit.

§Errors

DbError if the query fails or a row doesn’t read.

Source§

impl Database

Source

pub async fn heartbeat_master( &self, master: &MasterNode<'_>, now: Timestamp, ) -> Result<(), DbError>

As Self::heartbeat_master_keeping, rows kept for MASTER_ROW_KEPT.

§Errors

DbError::Sqlx if a statement fails.

Source

pub async fn heartbeat_master_keeping( &self, master: &MasterNode<'_>, now: Timestamp, kept: SignedDuration, ) -> Result<(), DbError>

Writes master’s heartbeat (its row, made or brought up to date), and removes the rows of masters not heard from for kept (SCHEDR_HIDDEN__MASTER__NODE_ROW_KEPT). A standby heartbeats too: called on a database not fenced.

§Errors

DbError::Sqlx if a statement fails.

Source

pub async fn masters( &self, since: Timestamp, ) -> Result<Vec<MasterRecord>, DbError>

The masters heard from since since, the leader (the lease’s holder, its lease not expired, by the database’s clock) first, then by ID.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn set_worker_node( &self, worker_id: &str, master_id: Option<&str>, process_id: Option<&str>, config: Option<&Value>, ) -> Result<(), DbError>

Records the node a worker runs as: the master it registered with, its process and its configuration (masked); each None when not known (an older agent sends neither).

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn worker_nodes(&self) -> Result<Vec<WorkerNode>, DbError>

Every worker’s node, by ID.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn set_worker_usage( &self, worker_id: &str, usage: &WorkerUsage, now: Timestamp, ) -> Result<(), DbError>

Records what a worker uses, by part (decision 463), as measured now.

§Errors

DbError::Sqlx if the statement fails.

Source§

impl Database

Source

pub async fn queue_notifications( &self, notifications: &[NewNotification], now: Timestamp, ) -> Result<(), DbError>

Queues notifications, due now.

§Errors

DbError::Sqlx if a statement fails.

Source

pub async fn due_notifications( &self, now: Timestamp, limit: u32, ) -> Result<Vec<Notification>, DbError>

At most limit notifications due at now, the earliest due first.

§Errors

DbError if the query fails or a row doesn’t read.

Source

pub async fn delete_notification(&self, id: &str) -> Result<(), DbError>

Deletes notification id: delivered, or given up on.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn retry_notification( &self, id: &str, next_try_at: Timestamp, error: &str, ) -> Result<(), DbError>

Notification id failed with error: tried again from next_try_at.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn count_attempt_notification( &self, attempt_id: &str, max: u32, ) -> Result<bool, DbError>

Counts a notification attempt attempt_id sends itself, if it has sent fewer than max: whether it may.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn first_notification_request( &self, attempt_id: &str, request_key: &str, ) -> Result<bool, DbError>

Records attempt attempt_id’s call request_key: whether it is new (one sent again isn’t).

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn previous_run_failed( &self, dag_id: &str, run_id: &str, ) -> Result<bool, DbError>

Whether the DAG’s run that ended last before run_id failed (for RUN_RECOVERED).

§Errors

DbError::Sqlx if the query fails.

Source

pub async fn failed_tasks( &self, run_id: &str, limit: u32, ) -> Result<Vec<FailedTask>, DbError>

At most limit failed tasks of run run_id, with their last attempt’s error summary: a mapped task’s failed instances one by one (its own row only when none of them failed: it failed as a whole, its expansion say).

§Errors

DbError::Sqlx if the query fails.

Source

pub async fn instance_error( &self, instance_id: &str, ) -> Result<Option<String>, DbError>

The error summary of task instance instance_id’s last attempt, if it has one.

§Errors

DbError::Sqlx if the query fails.

Source§

impl Database

Source

pub async fn probe(&self, now: Timestamp) -> Result<Probe, DbError>

What the probe finds at now (decision 485).

§Errors

DbError if the statement fails.

Source

pub async fn exists( &self, check: Check, now: Timestamp, ) -> Result<bool, DbError>

Whether check’s read would find anything at now: its one EXISTS alone, for a loop that needs only it (the trigger loop, decision 486).

§Errors

DbError if the statement fails.

Source

pub async fn in_round<F: Future>( &self, now: Timestamp, ahead: Duration, work: F, ) -> F::Output

Runs work as a master’s round at now: its reads that the probe says find nothing are skipped (decision 485). The probe is taken at the first such read, looking ahead (the tick: a time-bounded check counts what is due by then), and again after any write transaction ended since, or for a time-bounded read past what it covered.

Source

pub async fn skipped(&self, check: Check) -> Result<bool, DbError>

Whether this read, check’s, is skipped: inside a round on this database whose probe found nothing for it (taking the probe first if none is current).

§Errors

DbError if the probe fails.

Source

pub async fn skipped_at( &self, check: Check, now: Timestamp, ) -> Result<bool, DbError>

As Self::skipped, for a read bounded by now (what is due by then): a probe taken for an earlier time is taken again.

§Errors

DbError if the probe fails.

Source§

impl Database

Source

pub async fn runs(&self, filter: &RunFilter) -> Result<Vec<RunRecord>, DbError>

Runs of every DAG (or one), newest triggered first, filtered by filter.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn run_dag_json(&self, run_id: &str) -> Result<Option<Value>, DbError>

The DAG JSON of the version a run ran with (its graph); None for an unknown run.

§Errors

DbError if the query fails or the stored JSON doesn’t read.

Source

pub async fn run_dag(&self, run_id: &str) -> Result<Option<Arc<Dag>>, DbError>

The DAG a run runs, parsed once per version (the cache’s, see Database::dag_version); None for no such run (B137: each task read parsed it).

§Errors

DbError if the query fails or the stored DAG doesn’t read.

Source

pub async fn run_dag_ids( &self, run_ids: &[&str], ) -> Result<BTreeMap<String, String>, DbError>

The DAG of each of run_ids that exists, by run (M5.1d: a group’s wait steps cleared with one read, where Self::run_dag reads a run’s DAG whole).

§Errors

DbError if the query fails.

Source

pub async fn mapped_instances( &self, run_id: &str, task_id: &TaskId, ) -> Result<usize, DbError>

How many instances mapped task task_id has in a run (its whole row not counted).

§Errors

DbError if the query fails.

Source

pub async fn run_task_output( &self, run_id: &str, task_id: &TaskId, ) -> Result<Option<(String, Value)>, DbError>

A task’s stored output in a run, with its outcome; None when it has none (yet).

§Errors

DbError if the query fails or the stored value doesn’t read.

Source

pub async fn instance_output( &self, run_id: &str, task_id: &TaskId, map_index: i32, ) -> Result<Option<(String, Value)>, DbError>

One task instance’s stored output in a run, with its outcome; None when it has none (yet).

§Errors

DbError if the query fails or the stored value doesn’t read.

Source

pub async fn outputs_deleted(&self, run_id: &str) -> Result<bool, DbError>

Whether [retention] outputs deleted run run_id’s outputs (decision 435).

§Errors

DbError::Sqlx if the query fails.

Source

pub async fn dag_runs( &self, dag_id: &DagId, planned_for: Option<Timestamp>, limit: u32, ) -> Result<Vec<RunRecord>, DbError>

A DAG’s runs, newest planned_for first, at most limit (capped at MAX_RUNS); only those for planned_for when given.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn run_record( &self, run_id: &str, ) -> Result<Option<RunRecord>, DbError>

A run by ID.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn run_instances( &self, run_id: &str, ) -> Result<Vec<InstanceRecord>, DbError>

A run’s task instances, in task ID order, then map_index order (a mapped task as a whole first).

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn run_code_hashes( &self, run_id: &str, ) -> Result<Vec<String>, DbError>

The code hashes a run’s attempts ran with, in the order first used (more than one: its tasks ran on different code).

§Errors

DbError::Sqlx if the query fails.

Source

pub async fn state_counts(&self) -> Result<StateCounts, DbError>

How many runs (by state and kind), task instances of unfinished runs and workers (by state) there are.

§Errors

DbError::Sqlx if a query fails.

Source

pub async fn task_attempts( &self, run_id: &str, task_id: &TaskId, ) -> Result<Vec<AttemptRecord>, DbError>

The attempts of a run’s task, oldest first.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn instance_attempts( &self, run_id: &str, task_id: &TaskId, map_index: i32, ) -> Result<Vec<AttemptRecord>, DbError>

The attempts of one task instance of a run, oldest first.

§Errors

DbError if the query fails or stored data doesn’t read.

Source§

impl Database

Source

pub async fn delete_old_runs( &self, before: Timestamp, batch: u32, ) -> Result<u64, DbError>

Deletes at most batch finished runs of one DAG that ended before before and aren’t kept, with their tasks, attempts and outputs; a run they started (TriggerDagOperator) loses its link to them (decision 431). Then the backfills left without runs, made before before. Gives how many runs: 0 when none is left.

§Errors

DbError if a statement fails (nothing of the batch is deleted then).

Source

pub async fn delete_old_outputs( &self, before: Timestamp, batch: u32, now: Timestamp, ) -> Result<u64, DbError>

Deletes the outputs of at most batch finished runs of one DAG that ended before before and aren’t kept, marking each run (outputs_deleted_at = now): its tasks and outcomes stay, and an output asked for answers “deleted by retention” (decision 435). Gives how many runs: 0 when none is left.

§Errors

DbError if a statement fails.

Source

pub async fn delete_unused_versions(&self) -> Result<u64, DbError>

Deletes the versions of one DAG that it doesn’t run now and no run or trigger uses, its row locked: a definition of the same code again stores its version anew (archived Retention: DAG versions). Gives how many: 0 when no DAG has any left.

§Errors

DbError if a statement fails.

Source

pub async fn delete_old_events( &self, before: Timestamp, batch: u32, ) -> Result<u64, DbError>

Deletes at most batch events triggers found and at most batch events posted through the API before before (decision 434), with what triggers passed of the posted ones. Gives how many in all.

§Errors

DbError if a statement fails.

Source

pub async fn delete_old_commands( &self, before: Timestamp, batch: u32, ) -> Result<u64, DbError>

Deletes at most batch commands decided (applied or rejected) that were asked for before before: the audit trail, kept apart from the runs. Gives how many.

§Errors

DbError if the statement fails.

Source

pub async fn delete_removed_dags( &self, before: Timestamp, ) -> Result<u64, DbError>

Deletes the DAGs removed before before that have no run left, with everything kept about them (versions, backfills, events, their trigger, wait step strikes): one whose ID appears again starts with no history. Gives how many.

§Errors

DbError if a statement fails.

Source§

impl Database

Source

pub async fn runs_of( &self, dag: &str, task: Option<&str>, matching: Matching, ) -> Result<Vec<OtherRun>, DbError>

The run of dag that matching picks (the newest planned for the moment, or the first to end after it), with its state, or task’s state in it; none yet: empty.

§Errors

DbError if the query fails.

Source

pub async fn park_wait( &self, instance_id: &str, look_at: Timestamp, __arg3: (Option<&str>, Option<&str>), ) -> Result<(), DbError>

Parks a wait_for step the master holds before looking at it (decision 487): the round skips it until look_at (its max_wait deadline), or until what it waits for, run or task of DAG waits_dag ending or event waits_event posted, clears it. Stored first, so what ends after the look clears it, and what ended before is seen by the look. Only a queued instance is parked.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn ready_since( &self, instance_id: &str, ) -> Result<Option<Timestamp>, DbError>

Since when a queued task instance is ready, if it is.

§Errors

DbError if the query fails or the stored time doesn’t read.

Source

pub async fn succeeded_since( &self, of: (&str, Option<&str>), started: &str, from: RunOfFrom<'_>, limit: u32, ) -> Result<Vec<(String, Timestamp, Timestamp)>, DbError>

The runs of dag (or of its task) that succeeded after after (or, without it, since since), oldest first, to limit, that haven’t started a run of started yet (decision 353): with each its planned_for and when it (or its task) ended. after is strict, by end and run ID, so a run is never read twice, events kept or not.

§Errors

DbError if the query fails or a stored time doesn’t read.

Source

pub async fn ended_since( &self, of: (&str, Option<&str>), from: RunOfFrom<'_>, limit: u32, ) -> Result<Vec<(String, Timestamp, Timestamp)>, DbError>

As Self::succeeded_since, every run that ended, whatever its state: what an @trigger(wait_for=...)’s function is called for.

§Errors

DbError if the query fails or a stored time doesn’t read.

Source

pub async fn live_since(&self, dag: &str) -> Result<Option<Timestamp>, DbError>

Since when a DAG has been live: unpaused and defined without a break (decision 353).

§Errors

DbError if the query fails or the stored time doesn’t read.

Source

pub async fn run_of_seen( &self, dag: &str, source: &str, ) -> Result<Option<RunOfSeen>, DbError>

How far a trigger=RunOf(...) reading source has looked: the last run it started one for. A cursor of another source (the trigger changed) counts as none.

§Errors

DbError if the query fails or the stored time doesn’t read.

Source

pub async fn set_run_of_seen( &self, dag: &str, source: &str, seen: &RunOfSeen, ) -> Result<(), DbError>

Records the last run a trigger=RunOf(...) reading source started one for, on its triggers row.

§Errors

DbError::Sqlx if the statement fails.

Source§

impl Database

Source

pub async fn sensor_wait( &self, instance_id: &str, now: Timestamp, ) -> Result<Option<SensorWait>, DbError>

Where an @sensor(wait_for=RunOf(...)) instance stands, its waiting starting now if it hadn’t (decision 353).

§Errors

DbError if a statement fails or a stored time doesn’t read.

Source

pub async fn hand_run( &self, instance_id: &str, run_id: &str, ended_at: Timestamp, ) -> Result<(), DbError>

Records the run handed to an @sensor(wait_for=...)’s function as it is assigned, and when it (or its task) ended. It waits no more: its park is dropped (decision 487), so a round that couldn’t assign it (no free slot, the round’s assignments made) leaves it for the next (Grok’s review of M5.1f2).

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn not_yet(&self, instance_id: &str) -> Result<(), DbError>

Records that the function returned NOT_YET for the run it was handed: the next call is for a later one.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn run_result( &self, run_id: &str, task: Option<&TaskId>, ) -> Result<Option<Value>, DbError>

What an @sensor(wait_for=...)‘s function is given of run_id (its RunResult): the run’s ID, DAG, planned_for, state and end, and with task that task’s state, outcome and output (a mapped task’s, the list of its elements’). None for a run gone.

§Errors

DbError if a query fails or what is stored doesn’t read.

Source§

impl Database

Source

pub async fn hand_trigger_run( &self, dag: &str, seen: &RunOfSeen, ) -> Result<(), DbError>

Records the run an @trigger(wait_for=...) of dag was given, as it is placed: what its clean end moves it past, or a skip passes (decision 353).

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn trigger_run_handed( &self, dag: &str, ) -> Result<Option<RunOfSeen>, DbError>

The run an @trigger(wait_for=...) of dag was last given and hasn’t passed yet.

§Errors

DbError if the query fails or the stored time doesn’t read.

Source

pub async fn pass_trigger_run( &self, dag: &str, source: &str, skipped: Option<&str>, call: Option<&str>, ) -> Result<bool, DbError>

Moves an @trigger(wait_for=...) of dag reading source past the run it was given: done with it, or passing it (skipped: why, kept as its last error). Its failures in a row start again. With call, ends that call in the same statement, so the call can’t end without the run passed (Codex’s review); without, only while no call runs. Gives whether it was passed.

§Errors

DbError::Sqlx if the statement fails.

Source§

impl Database

Source

pub async fn pass_trigger_run_stored( &self, dag: &str, source: &str, call: &str, ) -> Result<bool, DbError>

An @trigger(wait_for=...) of dag whose call call returned an event the master has stored: its item is passed, the call left running (its end passes nothing more). Gives whether it was passed.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn trigger_call_refused( &self, dag: &str, error: &str, not_before: Option<Timestamp>, ) -> Result<(), DbError>

An @trigger(wait_for=...) of dag whose call couldn’t be made for its run (too big to send): a failure with error, not started again before not_before.

§Errors

DbError::Sqlx if the statement fails.

Source§

impl Database

Source

pub async fn insert_run( &self, run: &NewRun<'_>, ) -> Result<Option<String>, DbError>

Creates a run and returns its ID; None if it is a scheduled run for a planned_for that already has one.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn insert_run_as( &self, id: &str, run: &NewRun<'_>, ) -> Result<Option<String>, DbError>

As Self::insert_run, with the run’s ID given (a command’s, so applying it again finds the run it made); None also when a run with this ID exists.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn run_params(&self, run_id: &str) -> Result<Option<Value>, DbError>

A run’s parameters, as stored JSON (decision 138); None for an unknown run.

§Errors

DbError if the query fails or the stored JSON doesn’t read.

Source

pub async fn last_scheduled_for( &self, dag_id: &DagId, ) -> Result<Option<Timestamp>, DbError>

The latest planned_for of the DAG’s scheduled runs: the scheduler’s bookkeeping, which manual and backfill runs never change.

§Errors

DbError if the query fails or the stored time doesn’t read.

Source

pub async fn nearest_earlier_run( &self, dag_id: &DagId, before: Timestamp, ) -> Result<Option<Timestamp>, DbError>

The planned_for of the DAG’s run nearest before before, of any kind.

§Errors

DbError if the query fails or the stored time doesn’t read.

Source

pub async fn running_count(&self, dag_id: &DagId) -> Result<u32, DbError>

How many of the DAG’s runs are running (what max_active_runs limits).

§Errors

DbError::Sqlx if the query fails.

Source

pub async fn queued_runs( &self, dag_id: &DagId, ) -> Result<Vec<QueuedRun>, DbError>

The DAG’s queued runs, oldest first.

§Errors

DbError if the query fails or a stored value doesn’t read.

Source

pub async fn run_overview(&self) -> Result<RunOverview, DbError>

Every DAG’s running count, latest scheduled planned_for and queued runs, in three queries: what a scheduler round reads, instead of three queries per DAG (B12). The master is the only writer of runs, so the round can work from it until it ends.

§Errors

DbError if a query fails or a stored value doesn’t read.

Source

pub async fn run_overview_of( &self, dags: &[&DagId], ) -> Result<RunOverview, DbError>

As Self::run_overview, for dags only (a round visiting some DAGs, see archive/PROJECT.md, “Quiet DAGs”): its cost follows them, not every DAG. Nothing for no DAGs.

§Errors

DbError if a query fails or a stored value doesn’t read.

Source

pub async fn runs_in_progress( &self, dag_id: &DagId, ) -> Result<Vec<String>, DbError>

The DAG’s runs not finished (queued or running), oldest first.

§Errors

DbError::Sqlx if the query fails.

Source

pub async fn mark_late_failure( &self, run_id: &str, reason: &str, ) -> Result<Option<String>, DbError>

Marks a run that ended success as a yellow success (decision 309), once, with why (late_cleanup_failed). Returns its DAG when this call marked it; None if it isn’t an ended success or is marked already.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn start_run( &self, run_id: &str, now: Timestamp, ) -> Result<(), DbError>

Starts a queued run: it becomes running.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn active_dags(&self) -> Result<Vec<ActiveDag>, DbError>

The DAGs the scheduler looks at: not removed, not in conflict, with a current version; in DAG ID order.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn dags_with_queued_runs(&self) -> Result<Vec<DagId>, DbError>

The DAGs with queued runs (from any source: manual, chained, event, backfill), by the partial index of unfinished runs: what wakes a quiet DAG whatever stored the run.

§Errors

DbError if the query fails or a stored DAG ID doesn’t read.

Source

pub async fn active_dag_versions(&self) -> Result<Vec<(DagId, String)>, DbError>

The ID and current version of every DAG the scheduler looks at (as Self::active_dags, without their definitions): one small query, for the quiet DAGs’ check against memory.

§Errors

DbError if the query fails or a stored DAG ID doesn’t read.

Source

pub async fn active_dags_of( &self, dags: &[&DagId], ) -> Result<Vec<ActiveDag>, DbError>

As Self::active_dags, for dags only: those of them that can run.

§Errors

DbError if the query fails or stored data doesn’t read.

Source§

impl Database

Source

pub async fn sample_sources( &self, masters_since: Timestamp, workers_since: Timestamp, ) -> Result<Vec<Source>, DbError>

What the leader samples (decision 464): the masters heard from since masters_since and the active or draining workers heard from since workers_since, each with the usage it last stored; none without one.

§Errors

DbError if a query fails or stored data doesn’t read.

Source

pub async fn insert_samples(&self, samples: &[Sample]) -> Result<(), DbError>

Stores samples; one already stored for its process, step and time is kept.

§Errors

DbError::Sqlx if a statement fails.

Source

pub async fn oldest_minute_sample(&self) -> Result<Option<Timestamp>, DbError>

The oldest minute sample’s time; none without one.

§Errors

DbError if the query fails or the time doesn’t read.

Source

pub async fn delete_old_samples( &self, step_s: u32, before: Timestamp, ) -> Result<u64, DbError>

Deletes the samples of step step_s older than before; how many.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn samples( &self, step_s: u32, from: Timestamp, to: Timestamp, ) -> Result<Vec<Sample>, DbError>

The samples of step step_s in [from, to), by process, then time.

§Errors

DbError if the query fails or a row doesn’t read.

Source

pub async fn samples_of( &self, step_s: u32, from: Timestamp, to: Timestamp, process: Option<&str>, ) -> Result<Vec<Sample>, DbError>

As Self::samples, of one process only when process names it.

§Errors

DbError if the query fails or a row doesn’t read.

Source

pub async fn sample_buckets( &self, __arg1: (Timestamp, Timestamp, Timestamp), bucket_s: u32, process: Option<&str>, ) -> Result<Vec<Bucket>, DbError>

Each process’s samples in [from, to) in buckets of bucket_s seconds (M5.1j): the rollups before cut, the minutes from it (those not rolled up yet; cut = from for minutes only), of one process when process names it. Averages are weighted by the minutes each row covers; peaks are the highest; the limit the highest in the bucket.

§Errors

DbError if the query fails or a row doesn’t read.

Source

pub async fn latest_of( &self, from: Timestamp, to: Timestamp, process: Option<&str>, ) -> Result<BTreeMap<String, Latest>, DbError>

Each process sampled in [from, to) as its latest sample there says: its roles and its container’s limit (none: unlimited).

§Errors

DbError if the query fails or a row doesn’t read.

Source

pub async fn rolled_up_to(&self) -> Result<Option<Timestamp>, DbError>

The end of the newest rollup’s window; none without one.

§Errors

DbError if the query fails or the time doesn’t read.

Source

pub async fn memory_totals( &self, __arg1: (Timestamp, Timestamp, Timestamp), bucket_s: u32, ) -> Result<Vec<(Timestamp, u64)>, DbError>

Every process’s whole memory together in buckets of bucket_s seconds over [from, to), rollups before cut and minutes from it (the Deployments page’s sparkline, M5.1j), oldest first: each process’s memory weighted by the minutes it was sampled, over the minutes the deployment was sampled in the bucket, so a process replaced within a bucket isn’t counted twice.

§Errors

DbError if the query fails or a time doesn’t read.

Source§

impl Database

Source

pub async fn atomically<T, E>( &self, work: impl Future<Output = Result<T, E>>, ) -> Result<T, E>
where E: From<DbError>,

Runs work in one transaction of this database: every query it makes on it (writes and reads) goes through the transaction, which commits when work returns Ok and rolls back when it returns Err (then nothing of it is stored). A fenced database checks its lease once, at the start, and on Postgres holds the lease’s row until the end (see Database::fenced). Already inside one on this database, work joins it.

§Errors

work’s error, or DbError if the transaction can’t start or commit (DbError::NotLeading for a master whose lease was taken over; DbError::CommitUnknown for a commit cut off, which may have stored it).

Source§

impl Database

Source

pub async fn set_secret( &self, key: &SecretKey, path: &str, values: &BTreeMap<String, String>, now: Timestamp, ) -> Result<(), SecretsError>

Sets values in the secret at path, encrypted under key: the given keys are written, the others kept (the secret is made if it doesn’t exist).

§Errors

SecretsError if a value can’t be encrypted or the database fails.

Source

pub async fn secret( &self, key: &SecretKey, path: &str, ) -> Result<Option<BTreeMap<String, String>>, SecretsError>

The secret at path, its values decrypted; None if there is none.

§Errors

SecretsError if a value doesn’t decrypt under key or the database fails.

Source

pub async fn secret_entries( &self, prefix: &str, ) -> Result<Vec<SecretEntry>, DbError>

The secrets whose path starts with prefix, by path: their key names, never values.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn delete_secret(&self, path: &str) -> Result<bool, DbError>

Removes the secret at path; false if there was none.

§Errors

DbError::Sqlx if the statement fails.

Source§

impl Database

Source

pub async fn wait_step_strikes( &self, dag_id: &str, task_id: &str, ) -> Result<Option<WaitStepStrikes>, DbError>

A wait step’s strikes, if it has any.

§Errors

DbError if the statement fails.

Source

pub async fn switched_off_wait_steps( &self, ) -> Result<Vec<WaitStepStrikes>, DbError>

The wait steps switched off now, by DAG and task.

§Errors

DbError if the statement fails.

Source

pub async fn strike_wait_step( &self, __arg1: (&str, &str), limit: u32, code: &str, now: Timestamp, ) -> Result<bool, DbError>

Counts a strike; at limit in a row (0: never), or on its one chance, it is switched off on code code. Returns whether it is off now.

§Errors

DbError if a statement fails.

Source

pub async fn wait_step_on_new_code( &self, dag_id: &str, task_id: &str, ) -> Result<(), DbError>

New code: on again, with one chance.

§Errors

DbError if the statement fails.

Source

pub async fn clear_wait_steps( &self, dag_id: &str, task_ids: &[&str], ) -> Result<(), DbError>

Clears the strikes of DAG dag_id’s wait steps task_ids, as Self::clear_wait_step does each, in one statement (M5.1d).

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn clear_wait_step( &self, dag_id: &str, task_id: &str, ) -> Result<bool, DbError>

Forgets its strikes (a success, or switched on by hand). Returns whether it had any.

§Errors

DbError if the statement fails.

Source§

impl Database

Source

pub async fn attempts_ended( &self, __arg1: (Timestamp, Timestamp), bucket_s: u32, ) -> Result<Vec<EndedCount>, DbError>

The attempts that ended in [from, to), counted by bucket of bucket_s seconds and by status, oldest first.

§Errors

DbError if the query fails.

Source

pub async fn start_latency( &self, __arg1: (Timestamp, Timestamp), bucket_s: u32, ) -> Result<Vec<StartLatency>, DbError>

The start latency of the attempts started in [from, to), by bucket of bucket_s seconds, oldest first: each bucket’s p50 and p95 (the nearest rank), exact.

§Errors

DbError if the query fails.

Source§

impl Database

Source

pub async fn task_attempt_peaks( &self, dag_id: &str, task_id: &str, count: u32, runs: u32, ) -> Result<Vec<AttemptPeak>, DbError>

The last count attempts of task_id of DAG dag_id to end, all its instances, the oldest first: of its runs ended last (SCHEDR_HIDDEN__WEBSERVER__MEMORY_PEAKS_RUNS, PEAKS_PER_TASK by default) and those still going.

§Errors

DbError if the query fails or a row doesn’t read.

Source

pub async fn dag_task_peaks( &self, dag_id: &str, since: Timestamp, runs: u32, ) -> Result<Vec<TaskPeaks>, DbError>

Each task of DAG dag_id with attempts ended since since, of its runs runs ended last since then and those still going: the peaks of its newest runs that have one, by task.

§Errors

DbError if the query fails.

Source§

impl Database

Source

pub async fn triggers(&self) -> Result<Vec<TriggerRecord>, DbError>

Every trigger the master has run, by DAG.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn trigger( &self, dag_id: &str, ) -> Result<Option<TriggerRecord>, DbError>

A DAG’s trigger, if it has run or found anything.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn trigger_assigned( &self, dag_id: &str, instance_id: &str, worker_id: &str, dag_version_id: &str, code_hash: &str, now: Timestamp, ) -> Result<(), DbError>

Records that a worker was given a DAG’s trigger.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn trigger_ended( &self, dag_id: &str, instance_id: &str, error: Option<&str>, not_before: Option<Timestamp>, ) -> Result<bool, DbError>

Records that this run of a DAG’s trigger ended, with why if it failed, and when it may start again; what isn’t this run any more is left alone. Gives whether it was.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn store_event( &self, run_id: &str, run: &NewRun<'_>, event: &RunEvent, ) -> Result<Option<String>, DbError>

Stores what a trigger found, in one transaction: the event; for a key not seen before, run; and the key as the bookmark, whichever it was. Gives the run’s ID, None for a repeat.

§Errors

DbError::Sqlx if a statement fails.

Source

pub async fn store_batch( &self, run_id: &str, run: &NewRun<'_>, key: &str, items: &[(RunEvent, Value)], ) -> Result<Option<String>, DbError>

Stores a batch a trigger found (@trigger.poke(batch=...), decision 352), in one transaction: each item as an event of its own; for the items whose keys weren’t seen before, run, its event their list as stored (raw), keyed by the last of them; and the batch’s key, its last item’s, as the bookmark. Gives the run’s ID, None when every item was seen before (B188: a window ending with a repeat lost the new items before it).

§Errors

DbError::Sqlx if a statement fails.

Source

pub async fn set_trigger_stopped( &self, dag_id: &str, why: Option<(&str, &str)>, ) -> Result<(), DbError>

Says why a trigger isn’t to run although its DAG wants it, and on what it stopped; None: it may run again.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn trigger_idle_restart( &self, dag_id: &str, now: Timestamp, ) -> Result<(), DbError>

Records that a trigger was started again for finding nothing for too long.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn trigger_poked( &self, dag_id: &str, instance_id: &str, at: Timestamp, error: Option<&str>, failures: u32, ) -> Result<(), DbError>

How a poke’s calls have gone: its failures in a row, and why the last one failed; one that went well clears them.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn queued_event_runs(&self) -> Result<Vec<(String, i64)>, DbError>

The queued runs of kind event, by DAG.

§Errors

DbError::Sqlx if the query fails.

Source

pub async fn restart_trigger(&self, dag_id: &str) -> Result<(), DbError>

Asks for a trigger to start again, whatever stopped it: what it waited for is forgotten, and one running looks as if of an older version, so the next pass stops it. None when it never ran.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn stored_event( &self, dag_id: &str, key: &str, ) -> Result<Option<RunEvent>, DbError>

An event of a DAG by its key, as stored.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn events( &self, dag_id: &str, limit: u32, after: Option<(Timestamp, &str)>, ) -> Result<Vec<StoredEvent>, DbError>

A DAG’s events, newest received first (then by key), to limit; those after the one at after, its time and key.

§Errors

DbError if the query fails or stored data doesn’t read.

Source

pub async fn queued_event_runs_of(&self, dag_id: &str) -> Result<i64, DbError>

A DAG’s queued runs of kind event.

§Errors

DbError::Sqlx if the query fails.

Source

pub async fn run_event(&self, run_id: &str) -> Result<Option<RunEvent>, DbError>

The event that started a run; None for a run no event started.

§Errors

DbError if the query fails or stored data doesn’t read.

Source§

impl Database

Source

pub async fn register_worker( &self, worker: &WorkerRegistration<'_>, now: Timestamp, ) -> Result<(), DbError>

Records a registration: the worker is active, with this incarnation and settings.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn worker_seen( &self, worker_id: &str, now: Timestamp, ) -> Result<(), DbError>

Records a sign of life from a worker.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn set_worker_warnings( &self, worker_id: &str, warnings: &[WorkerWarning], ) -> Result<(), DbError>

Replaces a worker’s warnings with what it reported now.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn set_worker_hosts( &self, worker_id: &str, hosts: &[WatcherHostRecord], ) -> Result<(), DbError>

Replaces what a worker’s hosts look like with what its heartbeat said now.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn set_worker_state( &self, worker_id: &str, state: WorkerState, now: Timestamp, ) -> Result<(), DbError>

Records a worker’s new state; going offline or lost also records when.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn set_worker_drained( &self, worker_id: &str, drained: bool, ) -> Result<bool, DbError>

Drains a worker for maintenance, or resumes it; whether it is in the registry.

§Errors

DbError::Sqlx if the statement fails.

Source

pub async fn resume_worker( &self, worker_id: &str, ) -> Result<Option<bool>, DbError>

Resumes a drained worker; whether it was drained (None for a worker not in the registry).

§Errors

DbError::Sqlx if a statement fails.

Source

pub async fn worker_drained(&self, worker_id: &str) -> Result<bool, DbError>

Whether a worker is drained for maintenance (false for one not in the registry).

§Errors

DbError::Sqlx if the query fails.

Source

pub async fn worker_log_endpoint( &self, worker_id: &str, ) -> Result<Option<(WorkerState, String)>, DbError>

Where one worker’s log endpoint is, and its state (what the webserver needs to read a log); None for a worker never registered.

§Errors

DbError if the query fails or the state doesn’t read.

Source

pub async fn workers(&self) -> Result<Vec<WorkerRecord>, DbError>

Every worker in the registry, by ID, with its running attempts counted.

§Errors

DbError if the query fails or stored data doesn’t read.

Trait Implementations§

Source§

impl Clone for Database

Source§

fn clone(&self) -> Database

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Database

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Pool> for Database

Source§

fn from(pool: Pool) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more