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
impl Database
Sourcepub async fn ready_instances(
&self,
now: Timestamp,
) -> Result<Vec<ReadyInstance>, DbError>
pub async fn ready_instances( &self, now: Timestamp, ) -> Result<Vec<ReadyInstance>, DbError>
Sourcepub async fn assign_attempt(
&self,
instance_id: &str,
worker_id: &str,
now: Timestamp,
) -> Result<Option<(String, u32)>, DbError>
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).
Sourcepub async fn claim_attempts(
&self,
claims: &[(&str, &str, &str)],
now: Timestamp,
) -> Result<BTreeMap<String, u32>, DbError>
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).
Sourcepub async fn start_chained_attempt(
&self,
instance_id: &str,
chained_run_id: &str,
now: Timestamp,
) -> Result<Option<(String, u32)>, DbError>
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).
Sourcepub async fn chained_attempts(&self) -> Result<Vec<ChainedAttempt>, DbError>
pub async fn chained_attempts(&self) -> Result<Vec<ChainedAttempt>, DbError>
Sourcepub async fn undo_assignment(
&self,
attempt_id: &str,
state: TaskInstanceState,
ready_at: Option<Timestamp>,
reason: Option<&str>,
now: Timestamp,
) -> Result<(), DbError>
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).
Sourcepub async fn first_starts(
&self,
instance_ids: &[&str],
) -> Result<BTreeMap<String, Timestamp>, DbError>
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.
Sourcepub async fn open_attempts(
&self,
worker_id: Option<&str>,
) -> Result<Vec<StoredAttempt>, DbError>
pub async fn open_attempts( &self, worker_id: Option<&str>, ) -> Result<Vec<StoredAttempt>, DbError>
Sourcepub async fn mark_replaced(
&self,
attempt_ids: &[String],
now: Timestamp,
) -> Result<(), DbError>
pub async fn mark_replaced( &self, attempt_ids: &[String], now: Timestamp, ) -> Result<(), DbError>
Sourcepub async fn clear_replaced(
&self,
attempt_ids: &[String],
) -> Result<(), DbError>
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.
Sourcepub async fn replaced_attempts(&self) -> Result<Vec<String>, DbError>
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.
Sourcepub async fn set_task_result(
&self,
attempt_id: &str,
result: &[u8],
) -> Result<(), DbError>
pub async fn set_task_result( &self, attempt_id: &str, result: &[u8], ) -> Result<(), DbError>
Sourcepub async fn add_cleanup_handles(
&self,
attempt_id: &str,
first: u32,
handles: &[String],
limit: usize,
) -> Result<bool, DbError>
pub async fn add_cleanup_handles( &self, attempt_id: &str, first: u32, handles: &[String], limit: usize, ) -> Result<bool, DbError>
Sourcepub async fn move_cleanup(
&self,
attempt_id: &str,
result: &[u8],
not_before: Timestamp,
) -> Result<(), DbError>
pub async fn move_cleanup( &self, attempt_id: &str, result: &[u8], not_before: Timestamp, ) -> Result<(), DbError>
Sourcepub async fn take_back_cleanup(
&self,
attempt_id: &str,
worker_id: &str,
drop_result: bool,
) -> Result<bool, DbError>
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.
Sourcepub async fn cleanup_moved_from(
&self,
attempt_id: &str,
) -> Result<Option<String>, DbError>
pub async fn cleanup_moved_from( &self, attempt_id: &str, ) -> Result<Option<String>, DbError>
Sourcepub async fn assign_cleanup(
&self,
attempt_id: &str,
worker_id: &str,
now: Timestamp,
) -> Result<bool, DbError>
pub async fn assign_cleanup( &self, attempt_id: &str, worker_id: &str, now: Timestamp, ) -> Result<bool, DbError>
Sourcepub async fn unstarted_cleanups(
&self,
cutoff: Timestamp,
except_workers: &[String],
limit: u32,
) -> Result<Vec<StoredAttempt>, DbError>
pub async fn unstarted_cleanups( &self, cutoff: Timestamp, except_workers: &[String], limit: u32, ) -> Result<Vec<StoredAttempt>, DbError>
Sourcepub async fn waiting_cleanups(
&self,
now: Timestamp,
) -> Result<Vec<(String, ReadyInstance)>, DbError>
pub async fn waiting_cleanups( &self, now: Timestamp, ) -> Result<Vec<(String, ReadyInstance)>, DbError>
Sourcepub async fn active_attempts(&self) -> Result<Vec<ActiveAttempt>, DbError>
pub async fn active_attempts(&self) -> Result<Vec<ActiveAttempt>, DbError>
Sourcepub async fn active_counts(
&self,
dag_id: &DagId,
) -> Result<Vec<(String, TaskId, u32)>, DbError>
pub async fn active_counts( &self, dag_id: &DagId, ) -> Result<Vec<(String, TaskId, u32)>, DbError>
Sourcepub async fn unstarted_attempts(
&self,
cutoff: Timestamp,
except_workers: &[String],
limit: u32,
) -> Result<Vec<StoredAttempt>, DbError>
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.
Sourcepub async fn mark_started(
&self,
attempt_id: &str,
start_method: &str,
at: Timestamp,
) -> Result<bool, DbError>
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.
Sourcepub async fn mark_started_many(
&self,
starts: &[(&str, Timestamp)],
start_method: &str,
) -> Result<BTreeSet<String>, DbError>
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.
Sourcepub async fn mark_adopted(
&self,
attempt_id: &str,
now: Timestamp,
) -> Result<(), DbError>
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.
Sourcepub async fn attempts_by_ids(
&self,
ids: &[&str],
) -> Result<Vec<StoredAttempt>, DbError>
pub async fn attempts_by_ids( &self, ids: &[&str], ) -> Result<Vec<StoredAttempt>, DbError>
Sourcepub async fn end_attempts(
&self,
ends: &[(&str, &AttemptEnd)],
now: Timestamp,
) -> Result<BTreeSet<String>, DbError>
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.
Sourcepub async fn end_attempt(
&self,
attempt_id: &str,
end: &AttemptEnd,
now: Timestamp,
) -> Result<bool, DbError>
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.
Sourcepub async fn add_rest_cleanup(
&self,
attempt_id: &str,
rest: &CleanupEnd,
) -> Result<bool, DbError>
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.
Sourcepub async fn upstream_outcomes(
&self,
run_id: &str,
tasks: &[&TaskId],
) -> Result<BTreeMap<TaskId, Option<String>>, DbError>
pub async fn upstream_outcomes( &self, run_id: &str, tasks: &[&TaskId], ) -> Result<BTreeMap<TaskId, Option<String>>, DbError>
Sourcepub async fn outputs_of(
&self,
run_id: &str,
tasks: &[&TaskId],
) -> Result<BTreeMap<TaskId, Value>, DbError>
pub async fn outputs_of( &self, run_id: &str, tasks: &[&TaskId], ) -> Result<BTreeMap<TaskId, Value>, DbError>
Sourcepub async fn ended_in_order(
&self,
run_id: &str,
tasks: &[&TaskId],
) -> Result<Vec<TaskId>, DbError>
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.
Sourcepub async fn instance_results(
&self,
run_id: &str,
task: &TaskId,
) -> Result<Vec<InstanceResult>, DbError>
pub async fn instance_results( &self, run_id: &str, task: &TaskId, ) -> Result<Vec<InstanceResult>, DbError>
Sourcepub async fn instance_result(
&self,
run_id: &str,
task: &TaskId,
map_index: i32,
) -> Result<Option<InstanceResult>, DbError>
pub async fn instance_result( &self, run_id: &str, task: &TaskId, map_index: i32, ) -> Result<Option<InstanceResult>, DbError>
Sourcepub async fn unschedulable_instances(
&self,
) -> Result<Vec<Unschedulable>, DbError>
pub async fn unschedulable_instances( &self, ) -> Result<Vec<Unschedulable>, DbError>
Sourcepub async fn requeue_unschedulable(
&self,
now: Timestamp,
) -> Result<u64, DbError>
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
impl Database
Sourcepub async fn insert_backfill(
&self,
backfill: &NewBackfill<'_>,
) -> Result<bool, DbError>
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.
Sourcepub async fn covered_times(
&self,
dag_id: &DagId,
from: Timestamp,
to: Timestamp,
) -> Result<BTreeSet<Timestamp>, DbError>
pub async fn covered_times( &self, dag_id: &DagId, from: Timestamp, to: Timestamp, ) -> Result<BTreeSet<Timestamp>, DbError>
Sourcepub async fn succeeded_times(
&self,
dag_id: &DagId,
from: Timestamp,
to: Timestamp,
) -> Result<BTreeSet<Timestamp>, DbError>
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.
Sourcepub async fn dag_backfills(
&self,
dag_id: &DagId,
limit: u32,
) -> Result<Vec<BackfillRecord>, DbError>
pub async fn dag_backfills( &self, dag_id: &DagId, limit: u32, ) -> Result<Vec<BackfillRecord>, DbError>
Sourcepub async fn unfinished_backfill_runs(
&self,
id: &str,
) -> Result<Vec<String>, DbError>
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
impl Database
Sourcepub async fn changes_reading(
&self,
poll: Duration,
rows: usize,
) -> Result<Option<Changes>, DbError>
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
impl Database
Sourcepub async fn change_notifications(&self) -> Result<bool, DbError>
pub async fn change_notifications(&self) -> Result<bool, DbError>
Sourcepub async fn set_change_notifications(&self, on: bool) -> Result<bool, DbError>
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
impl Database
Sourcepub async fn insert_command(
&self,
command: &Command,
requested_by: &str,
now: Timestamp,
) -> Result<String, DbError>
pub async fn insert_command( &self, command: &Command, requested_by: &str, now: Timestamp, ) -> Result<String, DbError>
Sourcepub async fn submit_command(
&self,
command: &Command,
requested_by: &str,
key: Option<&str>,
now: Timestamp,
) -> Result<Submitted, DbError>
pub async fn submit_command( &self, command: &Command, requested_by: &str, key: Option<&str>, now: Timestamp, ) -> Result<Submitted, DbError>
Sourcepub async fn command_notifications(
&self,
) -> Result<Option<CommandNotifications>, DbError>
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.
Sourcepub async fn pending_commands(
&self,
limit: u32,
) -> Result<Vec<PendingCommand>, DbError>
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.
Sourcepub async fn mark_applying(
&self,
id: &str,
now: Timestamp,
) -> Result<(), DbError>
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.
Sourcepub async fn decide_command(
&self,
id: &str,
status: CommandStatus,
reason: Option<&str>,
result: Option<&Value>,
now: Timestamp,
) -> Result<bool, DbError>
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.
Sourcepub async fn run_commands(
&self,
run_id: &str,
) -> Result<Vec<CommandRecord>, DbError>
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§impl Database
impl Database
Sourcepub async fn record_root_hash(
&self,
root: &str,
content_hash: &str,
switched: bool,
now: Timestamp,
) -> Result<(), DbError>
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.
Sourcepub async fn root_hash_switches(
&self,
root: &str,
) -> Result<BTreeMap<String, Timestamp>, DbError>
pub async fn root_hash_switches( &self, root: &str, ) -> Result<BTreeMap<String, Timestamp>, DbError>
Sourcepub async fn parses_of(
&self,
root: &str,
content_hash: &str,
) -> Result<Vec<StoredParse>, DbError>
pub async fn parses_of( &self, root: &str, content_hash: &str, ) -> Result<Vec<StoredParse>, DbError>
Sourcepub async fn find_parse(
&self,
root: &str,
content_hash: &str,
schedr_version: &str,
) -> Result<Option<String>, DbError>
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.
Sourcepub async fn insert_parse(
&self,
parse: &NewParse<'_>,
) -> Result<String, DbError>
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).
Sourcepub async fn replace_parse_files(
&self,
parse_id: &str,
files: &[ParsedFile],
worker_id: &str,
parsed_at: Timestamp,
) -> Result<(), DbError>
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.
Sourcepub async fn parse_file_workers(
&self,
parse_id: &str,
) -> Result<BTreeMap<String, String>, DbError>
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.
Sourcepub async fn parse_files(
&self,
parse_id: &str,
) -> Result<Vec<ParsedFile>, DbError>
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.
Sourcepub async fn current_connections(&self, root: &str) -> Result<Registry, DbError>
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.
Sourcepub async fn set_current_parse(
&self,
root: &str,
parse_id: &str,
now: Timestamp,
) -> Result<(), DbError>
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.
Sourcepub async fn current_parses(&self) -> Result<BTreeMap<String, String>, DbError>
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.
Sourcepub async fn current_import_errors(
&self,
) -> Result<Vec<ImportErrorRecord>, DbError>
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.
Sourcepub async fn stored_dags(&self) -> Result<Vec<StoredDag>, DbError>
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.
Sourcepub async fn held_dags(&self) -> Result<BTreeMap<String, bool>, DbError>
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.
Sourcepub async fn removed_dags_runs(&self) -> Result<Vec<String>, DbError>
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.
Sourcepub async fn scheduled_due(
&self,
now: Timestamp,
) -> Result<Vec<(DagId, Option<Timestamp>)>, DbError>
pub async fn scheduled_due( &self, now: Timestamp, ) -> Result<Vec<(DagId, Option<Timestamp>)>, DbError>
Sourcepub async fn claim_looks(
&self,
) -> Result<HashMap<DagId, Option<Timestamp>>, DbError>
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.
Sourcepub async fn set_next_fire_if(
&self,
dag_id: &DagId,
was: Timestamp,
at: Timestamp,
) -> Result<bool, DbError>
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.
Sourcepub async fn set_next_fire(
&self,
dag_id: &DagId,
at: Timestamp,
) -> Result<(), DbError>
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.
Sourcepub async fn stored_dag(
&self,
dag_id: &DagId,
) -> Result<Option<StoredDag>, DbError>
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.
Sourcepub async fn set_paused(
&self,
dag_id: &DagId,
paused: bool,
) -> Result<bool, DbError>
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.
Sourcepub async fn set_paused_at(
&self,
dag_id: &DagId,
paused: bool,
now: Timestamp,
) -> Result<bool, DbError>
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.
Sourcepub async fn apply_dag_changes(
&self,
changes: &[DagChange],
now: Timestamp,
) -> Result<(), DbError>
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
impl Database
Sourcepub async fn connect(url: &str) -> Result<Self, DbError>
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.
Sourcepub async fn connect_with_timeout(
url: &str,
query_timeout: Duration,
) -> Result<Self, DbError>
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.
Sourcepub fn fenced_as(&self) -> Option<&str>
pub fn fenced_as(&self) -> Option<&str>
The lease holder this database is fenced for (a master’s ID): None
if it isn’t.
Sourcepub fn fenced(&self, holder: &str, epoch: i64) -> Self
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).
Sourcepub async fn dag_version(&self, version_id: &str) -> Result<Arc<Dag>, DbError>
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.
Sourcepub fn with_notifications(self, on: bool, url: Option<String>) -> Self
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).
Sourcepub fn with_dag_versions_cached(self, most: usize) -> Self
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).
Sourcepub async fn changed(&self)
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).
Sourcepub async fn waits_due(&self)
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.
Sourcepub async fn quietly<F: Future>(&self, work: F) -> F::Output
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.
Sourcepub fn writes_ended(&self) -> u64
pub fn writes_ended(&self) -> u64
Write transactions ended so far, in this process (shared by clones).
Sourcepub fn query_timeout(&self) -> Duration
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).
Sourcepub async fn migrate(&self) -> Result<(), DbError>
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.
Sourcepub async fn migrate_as_lease_holder(&self) -> Result<(), DbError>
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.
Sourcepub async fn applied_migrations(&self) -> Result<Vec<i64>, DbError>
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.
Sourcepub async fn schema_status(&self) -> Result<SchemaStatus, DbError>
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
impl Database
Sourcepub async fn newly_running(&self) -> Result<Vec<NewlyRunning>, DbError>
pub async fn newly_running(&self) -> Result<Vec<NewlyRunning>, DbError>
Sourcepub async fn create_instances(
&self,
run_id: &str,
states: &[(TaskId, i32, TaskInstanceState)],
now: Timestamp,
) -> Result<(), DbError>
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).
Sourcepub async fn set_cleanup_result(
&self,
instance_id: &str,
result: CleanupResult,
now: Timestamp,
) -> Result<(), DbError>
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.
Sourcepub async fn update_instances(
&self,
run_id: &str,
updates: &[InstanceUpdate],
now: Timestamp,
) -> Result<(), DbError>
pub async fn update_instances( &self, run_id: &str, updates: &[InstanceUpdate], now: Timestamp, ) -> Result<(), DbError>
Sourcepub async fn set_queued_reasons(
&self,
reasons: &[(String, String)],
now: Timestamp,
) -> Result<(), DbError>
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.
Sourcepub async fn finish_run(
&self,
run_id: &str,
state: RunState,
now: Timestamp,
) -> Result<(), DbError>
pub async fn finish_run( &self, run_id: &str, state: RunState, now: Timestamp, ) -> Result<(), DbError>
Sourcepub async fn request_cancel(
&self,
run_id: &str,
now: Timestamp,
) -> Result<(), DbError>
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.
Sourcepub async fn request_task_cancel(
&self,
run_id: &str,
task_id: &TaskId,
now: Timestamp,
) -> Result<(), DbError>
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.
Sourcepub async fn map_sizes(
&self,
run_id: &str,
task_id: &TaskId,
) -> Result<Option<Vec<usize>>, DbError>
pub async fn map_sizes( &self, run_id: &str, task_id: &TaskId, ) -> Result<Option<Vec<usize>>, DbError>
Sourcepub async fn request_instance_cancel(
&self,
run_id: &str,
task_id: &TaskId,
map_index: i32,
now: Timestamp,
) -> Result<(), DbError>
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.
Sourcepub async fn retry_unschedulable(
&self,
run_id: &str,
__arg2: (&TaskId, Option<i32>),
now: Timestamp,
) -> Result<bool, DbError>
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.
Sourcepub async fn due_retries(
&self,
now: Timestamp,
) -> Result<Vec<(String, TaskId, i32)>, DbError>
pub async fn due_retries( &self, now: Timestamp, ) -> Result<Vec<(String, TaskId, i32)>, DbError>
Sourcepub async fn store_output(
&self,
instance_id: &str,
outcome: &str,
value: &Value,
) -> Result<(), DbError>
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.
Sourcepub async fn store_outputs(
&self,
outputs: &[(&str, &str, &Value)],
) -> Result<(), DbError>
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.
Sourcepub async fn store_task_output(
&self,
run_id: &str,
task_id: &TaskId,
outcome: &str,
value: &Value,
) -> Result<(), DbError>
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§impl Database
impl Database
Sourcepub async fn create_lease_table(&self) -> Result<(), DbError>
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.
Sourcepub async fn take_lease(
&self,
holder: &str,
period: Duration,
) -> Result<Option<i64>, DbError>
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.
Sourcepub async fn renew_lease(
&self,
holder: &str,
epoch: i64,
period: Duration,
) -> Result<bool, DbError>
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.
Sourcepub async fn lease_holder(&self) -> Result<Option<String>, DbError>
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.
Sourcepub async fn lease_held(&self) -> Result<Option<(String, String)>, DbError>
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.
Sourcepub async fn release_lease(&self, holder: &str) -> Result<(), DbError>
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
impl Database
Sourcepub async fn post_named_event(
&self,
event: &NewNamedEvent<'_>,
posted_by: &str,
request_key: Option<&str>,
now: Timestamp,
) -> Result<Posted, DbError>
pub async fn post_named_event( &self, event: &NewNamedEvent<'_>, posted_by: &str, request_key: Option<&str>, now: Timestamp, ) -> Result<Posted, DbError>
Sourcepub async fn named_events_unseen(
&self,
name: &str,
dag_id: &str,
since: Timestamp,
limit: u32,
) -> Result<Vec<NamedEvent>, DbError>
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.
Sourcepub async fn named_event_unpassed(
&self,
name: &str,
dag_id: &str,
since: Timestamp,
) -> Result<Option<NamedEvent>, DbError>
pub async fn named_event_unpassed( &self, name: &str, dag_id: &str, since: Timestamp, ) -> Result<Option<NamedEvent>, DbError>
Sourcepub async fn forget_passed_before(
&self,
dag_id: &str,
name: &str,
before: Timestamp,
) -> Result<u64, DbError>
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.
Sourcepub async fn first_named_event(
&self,
name: &str,
key: Option<&str>,
since: Timestamp,
after: Option<(Timestamp, &str)>,
) -> Result<Option<NamedEvent>, DbError>
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.
Sourcepub async fn next_named_event_for(
&self,
__arg1: (&str, Option<&str>),
since: Timestamp,
after: Timestamp,
__arg4: (SignedDuration, &str),
) -> Result<Option<NamedEvent>, DbError>
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.
Sourcepub async fn named_events_by_id(
&self,
id: &str,
) -> Result<Option<NamedEvent>, DbError>
pub async fn named_events_by_id( &self, id: &str, ) -> Result<Option<NamedEvent>, DbError>
Source§impl Database
impl Database
Sourcepub async fn heartbeat_master(
&self,
master: &MasterNode<'_>,
now: Timestamp,
) -> Result<(), DbError>
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.
Sourcepub async fn heartbeat_master_keeping(
&self,
master: &MasterNode<'_>,
now: Timestamp,
kept: SignedDuration,
) -> Result<(), DbError>
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.
Sourcepub async fn set_worker_node(
&self,
worker_id: &str,
master_id: Option<&str>,
process_id: Option<&str>,
config: Option<&Value>,
) -> Result<(), DbError>
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.
Sourcepub async fn worker_nodes(&self) -> Result<Vec<WorkerNode>, DbError>
pub async fn worker_nodes(&self) -> Result<Vec<WorkerNode>, DbError>
Sourcepub async fn set_worker_usage(
&self,
worker_id: &str,
usage: &WorkerUsage,
now: Timestamp,
) -> Result<(), DbError>
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
impl Database
Sourcepub async fn queue_notifications(
&self,
notifications: &[NewNotification],
now: Timestamp,
) -> Result<(), DbError>
pub async fn queue_notifications( &self, notifications: &[NewNotification], now: Timestamp, ) -> Result<(), DbError>
Sourcepub async fn due_notifications(
&self,
now: Timestamp,
limit: u32,
) -> Result<Vec<Notification>, DbError>
pub async fn due_notifications( &self, now: Timestamp, limit: u32, ) -> Result<Vec<Notification>, DbError>
Sourcepub async fn retry_notification(
&self,
id: &str,
next_try_at: Timestamp,
error: &str,
) -> Result<(), DbError>
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.
Sourcepub async fn count_attempt_notification(
&self,
attempt_id: &str,
max: u32,
) -> Result<bool, DbError>
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.
Sourcepub async fn first_notification_request(
&self,
attempt_id: &str,
request_key: &str,
) -> Result<bool, DbError>
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.
Sourcepub async fn previous_run_failed(
&self,
dag_id: &str,
run_id: &str,
) -> Result<bool, DbError>
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.
Sourcepub async fn failed_tasks(
&self,
run_id: &str,
limit: u32,
) -> Result<Vec<FailedTask>, DbError>
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.
Sourcepub async fn instance_error(
&self,
instance_id: &str,
) -> Result<Option<String>, DbError>
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
impl Database
Sourcepub async fn in_round<F: Future>(
&self,
now: Timestamp,
ahead: Duration,
work: F,
) -> F::Output
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.
Sourcepub async fn skipped_at(
&self,
check: Check,
now: Timestamp,
) -> Result<bool, DbError>
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
impl Database
Sourcepub async fn run_dag(&self, run_id: &str) -> Result<Option<Arc<Dag>>, DbError>
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.
Sourcepub async fn run_dag_ids(
&self,
run_ids: &[&str],
) -> Result<BTreeMap<String, String>, DbError>
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.
Sourcepub async fn mapped_instances(
&self,
run_id: &str,
task_id: &TaskId,
) -> Result<usize, DbError>
pub async fn mapped_instances( &self, run_id: &str, task_id: &TaskId, ) -> Result<usize, DbError>
Sourcepub async fn run_task_output(
&self,
run_id: &str,
task_id: &TaskId,
) -> Result<Option<(String, Value)>, DbError>
pub async fn run_task_output( &self, run_id: &str, task_id: &TaskId, ) -> Result<Option<(String, Value)>, DbError>
Sourcepub async fn instance_output(
&self,
run_id: &str,
task_id: &TaskId,
map_index: i32,
) -> Result<Option<(String, Value)>, DbError>
pub async fn instance_output( &self, run_id: &str, task_id: &TaskId, map_index: i32, ) -> Result<Option<(String, Value)>, DbError>
Sourcepub async fn outputs_deleted(&self, run_id: &str) -> Result<bool, DbError>
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.
Sourcepub async fn dag_runs(
&self,
dag_id: &DagId,
planned_for: Option<Timestamp>,
limit: u32,
) -> Result<Vec<RunRecord>, DbError>
pub async fn dag_runs( &self, dag_id: &DagId, planned_for: Option<Timestamp>, limit: u32, ) -> Result<Vec<RunRecord>, DbError>
Sourcepub async fn run_instances(
&self,
run_id: &str,
) -> Result<Vec<InstanceRecord>, DbError>
pub async fn run_instances( &self, run_id: &str, ) -> Result<Vec<InstanceRecord>, DbError>
Sourcepub async fn run_code_hashes(
&self,
run_id: &str,
) -> Result<Vec<String>, DbError>
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.
Sourcepub async fn state_counts(&self) -> Result<StateCounts, DbError>
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.
Sourcepub async fn task_attempts(
&self,
run_id: &str,
task_id: &TaskId,
) -> Result<Vec<AttemptRecord>, DbError>
pub async fn task_attempts( &self, run_id: &str, task_id: &TaskId, ) -> Result<Vec<AttemptRecord>, DbError>
Source§impl Database
impl Database
Sourcepub async fn delete_old_runs(
&self,
before: Timestamp,
batch: u32,
) -> Result<u64, DbError>
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).
Sourcepub async fn delete_old_outputs(
&self,
before: Timestamp,
batch: u32,
now: Timestamp,
) -> Result<u64, DbError>
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.
Sourcepub async fn delete_unused_versions(&self) -> Result<u64, DbError>
pub async fn delete_unused_versions(&self) -> Result<u64, DbError>
Sourcepub async fn delete_old_events(
&self,
before: Timestamp,
batch: u32,
) -> Result<u64, DbError>
pub async fn delete_old_events( &self, before: Timestamp, batch: u32, ) -> Result<u64, DbError>
Sourcepub async fn delete_old_commands(
&self,
before: Timestamp,
batch: u32,
) -> Result<u64, DbError>
pub async fn delete_old_commands( &self, before: Timestamp, batch: u32, ) -> Result<u64, DbError>
Sourcepub async fn delete_removed_dags(
&self,
before: Timestamp,
) -> Result<u64, DbError>
pub async fn delete_removed_dags( &self, before: Timestamp, ) -> Result<u64, DbError>
Source§impl Database
impl Database
Sourcepub async fn runs_of(
&self,
dag: &str,
task: Option<&str>,
matching: Matching,
) -> Result<Vec<OtherRun>, DbError>
pub async fn runs_of( &self, dag: &str, task: Option<&str>, matching: Matching, ) -> Result<Vec<OtherRun>, DbError>
Sourcepub async fn park_wait(
&self,
instance_id: &str,
look_at: Timestamp,
__arg3: (Option<&str>, Option<&str>),
) -> Result<(), DbError>
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.
Sourcepub async fn succeeded_since(
&self,
of: (&str, Option<&str>),
started: &str,
from: RunOfFrom<'_>,
limit: u32,
) -> Result<Vec<(String, Timestamp, Timestamp)>, DbError>
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.
Sourcepub async fn ended_since(
&self,
of: (&str, Option<&str>),
from: RunOfFrom<'_>,
limit: u32,
) -> Result<Vec<(String, Timestamp, Timestamp)>, DbError>
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.
Sourcepub async fn run_of_seen(
&self,
dag: &str,
source: &str,
) -> Result<Option<RunOfSeen>, DbError>
pub async fn run_of_seen( &self, dag: &str, source: &str, ) -> Result<Option<RunOfSeen>, DbError>
Sourcepub async fn set_run_of_seen(
&self,
dag: &str,
source: &str,
seen: &RunOfSeen,
) -> Result<(), DbError>
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
impl Database
Sourcepub async fn sensor_wait(
&self,
instance_id: &str,
now: Timestamp,
) -> Result<Option<SensorWait>, DbError>
pub async fn sensor_wait( &self, instance_id: &str, now: Timestamp, ) -> Result<Option<SensorWait>, DbError>
Sourcepub async fn hand_run(
&self,
instance_id: &str,
run_id: &str,
ended_at: Timestamp,
) -> Result<(), DbError>
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.
Sourcepub async fn not_yet(&self, instance_id: &str) -> Result<(), DbError>
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.
Sourcepub async fn run_result(
&self,
run_id: &str,
task: Option<&TaskId>,
) -> Result<Option<Value>, DbError>
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
impl Database
Sourcepub async fn hand_trigger_run(
&self,
dag: &str,
seen: &RunOfSeen,
) -> Result<(), DbError>
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.
Sourcepub async fn pass_trigger_run(
&self,
dag: &str,
source: &str,
skipped: Option<&str>,
call: Option<&str>,
) -> Result<bool, DbError>
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
impl Database
Sourcepub async fn pass_trigger_run_stored(
&self,
dag: &str,
source: &str,
call: &str,
) -> Result<bool, DbError>
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.
Sourcepub async fn trigger_call_refused(
&self,
dag: &str,
error: &str,
not_before: Option<Timestamp>,
) -> Result<(), DbError>
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
impl Database
Sourcepub async fn insert_run(
&self,
run: &NewRun<'_>,
) -> Result<Option<String>, DbError>
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.
Sourcepub async fn insert_run_as(
&self,
id: &str,
run: &NewRun<'_>,
) -> Result<Option<String>, DbError>
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.
Sourcepub async fn last_scheduled_for(
&self,
dag_id: &DagId,
) -> Result<Option<Timestamp>, DbError>
pub async fn last_scheduled_for( &self, dag_id: &DagId, ) -> Result<Option<Timestamp>, DbError>
Sourcepub async fn nearest_earlier_run(
&self,
dag_id: &DagId,
before: Timestamp,
) -> Result<Option<Timestamp>, DbError>
pub async fn nearest_earlier_run( &self, dag_id: &DagId, before: Timestamp, ) -> Result<Option<Timestamp>, DbError>
Sourcepub async fn running_count(&self, dag_id: &DagId) -> Result<u32, DbError>
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.
Sourcepub async fn run_overview(&self) -> Result<RunOverview, DbError>
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.
Sourcepub async fn run_overview_of(
&self,
dags: &[&DagId],
) -> Result<RunOverview, DbError>
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.
Sourcepub async fn runs_in_progress(
&self,
dag_id: &DagId,
) -> Result<Vec<String>, DbError>
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.
Sourcepub async fn mark_late_failure(
&self,
run_id: &str,
reason: &str,
) -> Result<Option<String>, DbError>
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.
Sourcepub async fn active_dag_versions(&self) -> Result<Vec<(DagId, String)>, DbError>
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.
Sourcepub async fn active_dags_of(
&self,
dags: &[&DagId],
) -> Result<Vec<ActiveDag>, DbError>
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
impl Database
Sourcepub async fn sample_sources(
&self,
masters_since: Timestamp,
workers_since: Timestamp,
) -> Result<Vec<Source>, DbError>
pub async fn sample_sources( &self, masters_since: Timestamp, workers_since: Timestamp, ) -> Result<Vec<Source>, DbError>
Sourcepub async fn insert_samples(&self, samples: &[Sample]) -> Result<(), DbError>
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.
Sourcepub async fn oldest_minute_sample(&self) -> Result<Option<Timestamp>, DbError>
pub async fn oldest_minute_sample(&self) -> Result<Option<Timestamp>, DbError>
Sourcepub async fn delete_old_samples(
&self,
step_s: u32,
before: Timestamp,
) -> Result<u64, DbError>
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.
Sourcepub async fn samples(
&self,
step_s: u32,
from: Timestamp,
to: Timestamp,
) -> Result<Vec<Sample>, DbError>
pub async fn samples( &self, step_s: u32, from: Timestamp, to: Timestamp, ) -> Result<Vec<Sample>, DbError>
Sourcepub async fn samples_of(
&self,
step_s: u32,
from: Timestamp,
to: Timestamp,
process: Option<&str>,
) -> Result<Vec<Sample>, DbError>
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.
Sourcepub async fn sample_buckets(
&self,
__arg1: (Timestamp, Timestamp, Timestamp),
bucket_s: u32,
process: Option<&str>,
) -> Result<Vec<Bucket>, DbError>
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.
Sourcepub async fn latest_of(
&self,
from: Timestamp,
to: Timestamp,
process: Option<&str>,
) -> Result<BTreeMap<String, Latest>, DbError>
pub async fn latest_of( &self, from: Timestamp, to: Timestamp, process: Option<&str>, ) -> Result<BTreeMap<String, Latest>, DbError>
Sourcepub async fn rolled_up_to(&self) -> Result<Option<Timestamp>, DbError>
pub async fn rolled_up_to(&self) -> Result<Option<Timestamp>, DbError>
Sourcepub async fn memory_totals(
&self,
__arg1: (Timestamp, Timestamp, Timestamp),
bucket_s: u32,
) -> Result<Vec<(Timestamp, u64)>, DbError>
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
impl Database
Sourcepub async fn atomically<T, E>(
&self,
work: impl Future<Output = Result<T, E>>,
) -> Result<T, E>
pub async fn atomically<T, E>( &self, work: impl Future<Output = Result<T, E>>, ) -> Result<T, E>
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
impl Database
Sourcepub async fn set_secret(
&self,
key: &SecretKey,
path: &str,
values: &BTreeMap<String, String>,
now: Timestamp,
) -> Result<(), SecretsError>
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.
Sourcepub async fn secret(
&self,
key: &SecretKey,
path: &str,
) -> Result<Option<BTreeMap<String, String>>, SecretsError>
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.
Sourcepub async fn secret_entries(
&self,
prefix: &str,
) -> Result<Vec<SecretEntry>, DbError>
pub async fn secret_entries( &self, prefix: &str, ) -> Result<Vec<SecretEntry>, DbError>
Source§impl Database
impl Database
Sourcepub async fn wait_step_strikes(
&self,
dag_id: &str,
task_id: &str,
) -> Result<Option<WaitStepStrikes>, DbError>
pub async fn wait_step_strikes( &self, dag_id: &str, task_id: &str, ) -> Result<Option<WaitStepStrikes>, DbError>
Sourcepub async fn switched_off_wait_steps(
&self,
) -> Result<Vec<WaitStepStrikes>, DbError>
pub async fn switched_off_wait_steps( &self, ) -> Result<Vec<WaitStepStrikes>, DbError>
Sourcepub async fn strike_wait_step(
&self,
__arg1: (&str, &str),
limit: u32,
code: &str,
now: Timestamp,
) -> Result<bool, DbError>
pub async fn strike_wait_step( &self, __arg1: (&str, &str), limit: u32, code: &str, now: Timestamp, ) -> Result<bool, DbError>
Sourcepub async fn wait_step_on_new_code(
&self,
dag_id: &str,
task_id: &str,
) -> Result<(), DbError>
pub async fn wait_step_on_new_code( &self, dag_id: &str, task_id: &str, ) -> Result<(), DbError>
Sourcepub async fn clear_wait_steps(
&self,
dag_id: &str,
task_ids: &[&str],
) -> Result<(), DbError>
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§impl Database
impl Database
Sourcepub async fn attempts_ended(
&self,
__arg1: (Timestamp, Timestamp),
bucket_s: u32,
) -> Result<Vec<EndedCount>, DbError>
pub async fn attempts_ended( &self, __arg1: (Timestamp, Timestamp), bucket_s: u32, ) -> Result<Vec<EndedCount>, DbError>
Sourcepub async fn start_latency(
&self,
__arg1: (Timestamp, Timestamp),
bucket_s: u32,
) -> Result<Vec<StartLatency>, DbError>
pub async fn start_latency( &self, __arg1: (Timestamp, Timestamp), bucket_s: u32, ) -> Result<Vec<StartLatency>, DbError>
Source§impl Database
impl Database
Sourcepub async fn task_attempt_peaks(
&self,
dag_id: &str,
task_id: &str,
count: u32,
runs: u32,
) -> Result<Vec<AttemptPeak>, DbError>
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§impl Database
impl Database
Sourcepub 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>
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>
Sourcepub async fn trigger_ended(
&self,
dag_id: &str,
instance_id: &str,
error: Option<&str>,
not_before: Option<Timestamp>,
) -> Result<bool, DbError>
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.
Sourcepub async fn store_event(
&self,
run_id: &str,
run: &NewRun<'_>,
event: &RunEvent,
) -> Result<Option<String>, DbError>
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.
Sourcepub async fn store_batch(
&self,
run_id: &str,
run: &NewRun<'_>,
key: &str,
items: &[(RunEvent, Value)],
) -> Result<Option<String>, DbError>
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.
Sourcepub async fn set_trigger_stopped(
&self,
dag_id: &str,
why: Option<(&str, &str)>,
) -> Result<(), DbError>
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.
Sourcepub async fn trigger_idle_restart(
&self,
dag_id: &str,
now: Timestamp,
) -> Result<(), DbError>
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.
Sourcepub async fn trigger_poked(
&self,
dag_id: &str,
instance_id: &str,
at: Timestamp,
error: Option<&str>,
failures: u32,
) -> Result<(), DbError>
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.
Sourcepub async fn restart_trigger(&self, dag_id: &str) -> Result<(), DbError>
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.
Sourcepub async fn stored_event(
&self,
dag_id: &str,
key: &str,
) -> Result<Option<RunEvent>, DbError>
pub async fn stored_event( &self, dag_id: &str, key: &str, ) -> Result<Option<RunEvent>, DbError>
Sourcepub async fn events(
&self,
dag_id: &str,
limit: u32,
after: Option<(Timestamp, &str)>,
) -> Result<Vec<StoredEvent>, DbError>
pub async fn events( &self, dag_id: &str, limit: u32, after: Option<(Timestamp, &str)>, ) -> Result<Vec<StoredEvent>, DbError>
Source§impl Database
impl Database
Sourcepub async fn register_worker(
&self,
worker: &WorkerRegistration<'_>,
now: Timestamp,
) -> Result<(), DbError>
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.
Sourcepub async fn set_worker_warnings(
&self,
worker_id: &str,
warnings: &[WorkerWarning],
) -> Result<(), DbError>
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.
Sourcepub async fn set_worker_hosts(
&self,
worker_id: &str,
hosts: &[WatcherHostRecord],
) -> Result<(), DbError>
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.
Sourcepub async fn set_worker_state(
&self,
worker_id: &str,
state: WorkerState,
now: Timestamp,
) -> Result<(), DbError>
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.
Sourcepub async fn set_worker_drained(
&self,
worker_id: &str,
drained: bool,
) -> Result<bool, DbError>
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.
Sourcepub async fn resume_worker(
&self,
worker_id: &str,
) -> Result<Option<bool>, DbError>
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.
Sourcepub async fn worker_drained(&self, worker_id: &str) -> Result<bool, DbError>
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.
Sourcepub async fn worker_log_endpoint(
&self,
worker_id: &str,
) -> Result<Option<(WorkerState, String)>, DbError>
pub async fn worker_log_endpoint( &self, worker_id: &str, ) -> Result<Option<(WorkerState, String)>, DbError>
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Database
impl !UnwindSafe for Database
impl Freeze for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnsafeUnpin for Database
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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