Skip to main content

insert_schedule

Function insert_schedule 

Source
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 = false inserts version = 1; if the schedule was ever created, version 1 already exists and the unique violation yields Ok(None) so the caller can raise a friendly “already exists” error.
  • overwrite = true inserts a NEW row with version = max + 1, shadowing the older rows (they never list or run again, but stay for per-version run history). The fresh row has no tasks_runs entries, so it is immediately pending. A concurrent overwrite can collide on the computed version; retry a bounded number of times.