OXYGENHUB
# 50354f576ea6 oxygenflow / crates / flow-core / src / api.rs
2.2 KiB · Rust · last changed OxygenFlow M0: pipeline parser and canonical job graph, receipts, the runner API types, flow-init, the Firecracker tier, flow check, run, rootfs import and runner 1 month ago source blame history raw
1
//! The runner API between OxygenHub and `flow runner` (docs/m0.md §5).
2
//! Both sides use these types, so they cannot drift.
3
4
use crate::pipeline::{Job, Sandbox};
5
use crate::receipt::Receipt;
6
use serde::{Deserialize, Serialize};
7
8
/// `POST /api/v1/flow/claim`.
9
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
10
pub struct ClaimRequest {
11
    /// The runner's name, shown on job pages.
12
    pub runner: String,
13
    /// Tiers this runner can run (`microvm`, `syscall`).
14
    pub runtimes: Vec<String>,
15
}
16
17
/// A claimed job: everything the runner needs, nothing more.
18
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
19
pub struct Claim {
20
    pub job_id: i64,
21
    pub run_id: i64,
22
    /// `owner/name`.
23
    pub repo: String,
24
    /// Where to fetch the repository from (`oxy` wire protocol).
25
    pub clone_url: String,
26
    /// Read access to this repository only, until the job finishes.
27
    pub token: String,
28
    /// The state to build, as full change hashes.
29
    pub heads: Vec<String>,
30
    /// Hex BLAKE3 of the canonical pipeline.
31
    pub pipeline_hash: String,
32
    pub job: Job,
33
    pub sandbox: Sandbox,
34
    /// The hub's limit for this job.
35
    pub timeout_s: u64,
36
}
37
38
/// One line of output (docs/m0.md §2).
39
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
40
pub struct Record {
41
    /// Milliseconds since the job started.
42
    pub t: u64,
43
    /// `out`, `err`, `console` (the VM outside the job) or `flow` (the runner).
44
    pub stream: String,
45
    pub text: String,
46
}
47
48
/// `POST /api/v1/flow/jobs/{id}/log`.
49
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
50
pub struct LogBatch {
51
    pub records: Vec<Record>,
52
}
53
54
/// `POST /api/v1/flow/jobs/{id}/finish`.
55
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
56
pub struct Finish {
57
    /// The job's exit code; absent when the runner could not run it.
58
    pub exit_code: Option<i32>,
59
    pub duration_ms: u64,
60
    pub receipt: Option<Receipt>,
61
    /// Why the runner could not run the job (rootfs missing, VM failed).
62
    pub error: Option<String>,
63
}
64
65
/// Longest text of one record the hub keeps; longer lines are cut.
66
pub const MAX_RECORD_TEXT: usize = 16 * 1024;
67
/// Most records the hub keeps per job; later ones are dropped with a note.
68
pub const MAX_RECORDS: usize = 50_000;