//! The runner API between OxygenHub and `flow runner` (docs/m0.md §5). //! Both sides use these types, so they cannot drift. use crate::pipeline::{Job, Sandbox}; use crate::receipt::Receipt; use serde::{Deserialize, Serialize}; /// `POST /api/v1/flow/claim`. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct ClaimRequest { /// The runner's name, shown on job pages. pub runner: String, /// Tiers this runner can run (`microvm`, `syscall`). pub runtimes: Vec, /// Memory the runner has free for another job, in MiB: the hub hands /// out only a job whose sandbox fits. Absent: no limit. #[serde(default, skip_serializing_if = "Option::is_none")] pub free_memory_mib: Option, /// vCPUs the runner has free for another job. Absent: no limit. #[serde(default, skip_serializing_if = "Option::is_none")] pub free_cpus: Option, } /// A claimed job: everything the runner needs, nothing more. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Claim { pub job_id: i64, pub run_id: i64, /// `owner/name`. pub repo: String, /// Where to fetch the repository from (`oxy` wire protocol). pub clone_url: String, /// Read access to this repository only, until the job finishes. pub token: String, /// The state to build, as full change hashes. pub heads: Vec, /// Hex BLAKE3 of the canonical pipeline. pub pipeline_hash: String, pub job: Job, pub sandbox: Sandbox, /// The hub's limit for this job. pub timeout_s: u64, } /// One line of output (docs/m0.md §2). #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Record { /// Milliseconds since the job started. pub t: u64, /// `out`, `err`, `console` (the VM outside the job) or `flow` (the runner). pub stream: String, pub text: String, } /// `POST /api/v1/flow/jobs/{id}/log`. #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] pub struct LogBatch { pub records: Vec, } /// `POST /api/v1/flow/jobs/{id}/finish`. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Finish { /// The job's exit code; absent when the runner could not run it. pub exit_code: Option, pub duration_ms: u64, pub receipt: Option, /// The receipt bound to the job's state and signed by the runner /// (Oxygen spec §14.6), hex of the signed receipt's bytes. #[serde(default, skip_serializing_if = "Option::is_none")] pub signed_receipt: Option, /// Why the runner could not run the job (rootfs missing, VM failed). pub error: Option, } /// Longest text of one record the hub keeps; longer lines are cut. pub const MAX_RECORD_TEXT: usize = 16 * 1024; /// Most records the hub keeps per job; later ones are dropped with a note. pub const MAX_RECORDS: usize = 50_000;