pub async fn insert_schedule(
pool: &Pool,
name: &str,
command: &[String],
description: &str,
agent_instance_hierarchy: &str,
interval_seconds: Option<u64>,
agent_arguments: &AgentArguments,
plugin: Option<&PluginPath>,
overwrite: bool,
) -> Result<Option<(i64, i64)>, Error>Expand description
Insert one schedule row and return its (id, version).
command is JSON-serialised as a string array (the argv shape the
runner will exec). agent_arguments is JSON-serialised verbatim —
the runner re-installs each Some(_) field as the matching env var
when the schedule fires.
Versions are separate rows, unique on (name, aih, version):
overwrite = falseinsertsversion = 1; if the schedule was ever created, version 1 already exists and the unique violation yieldsOk(None)so the caller can raise a friendly “already exists” error.overwrite = trueinserts a NEW row withversion = max + 1, shadowing the older rows (they never list or run again, but stay for per-version run history). The fresh row has notasks_runsentries, so it is immediately pending. A concurrent overwrite can collide on the computed version; retry a bounded number of times.