| e0918b88 Andy McCall |
1 |
|
| 2 |
|
| 3 |
|
| 4 |
use crate::pipeline::{Job, Sandbox}; |
| 5 |
use crate::receipt::Receipt; |
| 6 |
use serde::{Deserialize, Serialize}; |
| 7 |
|
| 8 |
|
| 9 |
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
| 10 |
pub struct ClaimRequest { |
| 11 |
|
| 12 |
pub runner: String, |
| 13 |
|
| 14 |
pub runtimes: Vec<String>, |
| bb643c25 Andy McCall ↶ |
15 |
|
| 16 |
|
| 17 |
#[serde(default, skip_serializing_if = "Option::is_none")] |
| 18 |
pub free_memory_mib: Option<u32>, |
| 19 |
|
| 20 |
#[serde(default, skip_serializing_if = "Option::is_none")] |
| 21 |
pub free_cpus: Option<u32>, |
| e0918b88 Andy McCall |
22 |
} |
| 23 |
|
| c23d5191 Andy McCall ↶ |
24 |
|
| 25 |
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
| 26 |
pub struct SubrepoInput { |
| 27 |
pub path: String, |
| 28 |
|
| 29 |
pub repo: String, |
| 30 |
pub clone_url: String, |
| 31 |
pub heads: Vec<String>, |
| 32 |
} |
| 33 |
|
| e0918b88 Andy McCall |
34 |
|
| 35 |
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
| 36 |
pub struct Claim { |
| 37 |
pub job_id: i64, |
| 38 |
pub run_id: i64, |
| 39 |
|
| 40 |
pub repo: String, |
| 41 |
|
| 42 |
pub clone_url: String, |
| 43 |
|
| 44 |
pub token: String, |
| 45 |
|
| 46 |
pub heads: Vec<String>, |
| 47 |
|
| 48 |
pub pipeline_hash: String, |
| 49 |
pub job: Job, |
| 50 |
pub sandbox: Sandbox, |
| 51 |
|
| 52 |
pub timeout_s: u64, |
| c23d5191 Andy McCall ↶ |
53 |
|
| 54 |
|
| 55 |
#[serde(default, skip_serializing_if = "Vec::is_empty")] |
| 56 |
pub subrepos: Vec<SubrepoInput>, |
| c4285535 Andy McCall ↶ |
57 |
|
| 58 |
#[serde(default, skip_serializing_if = "String::is_empty")] |
| 59 |
pub state: String, |
| 60 |
|
| 61 |
#[serde(default, skip_serializing_if = "String::is_empty")] |
| 62 |
pub bookmark: String, |
| 63 |
|
| 64 |
#[serde(default)] |
| 65 |
pub run_number: i64, |
| 66 |
} |
| 67 |
|
| 68 |
impl Claim { |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
pub fn flow_env(&self) -> Vec<(String, String)> { |
| 74 |
let mut v = vec![ |
| 75 |
("FLOW_REPO".to_string(), self.repo.clone()), |
| 76 |
("FLOW_HEADS".to_string(), self.heads.join("+")), |
| 77 |
("FLOW_JOB".to_string(), self.job.name.clone()), |
| 78 |
]; |
| 79 |
if !self.state.is_empty() { |
| 80 |
v.push(("FLOW_STATE".into(), self.state.clone())); |
| 81 |
} |
| 82 |
if !self.bookmark.is_empty() { |
| 83 |
v.push(("FLOW_BOOKMARK".into(), self.bookmark.clone())); |
| 84 |
} |
| 85 |
if self.run_number > 0 { |
| 86 |
v.push(("FLOW_RUN".into(), self.run_number.to_string())); |
| 87 |
} |
| 88 |
v |
| 89 |
} |
| e0918b88 Andy McCall |
90 |
} |
| 91 |
|
| 92 |
|
| 93 |
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
| 94 |
pub struct Record { |
| 95 |
|
| 96 |
pub t: u64, |
| 97 |
|
| 98 |
pub stream: String, |
| 99 |
pub text: String, |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] |
| 104 |
pub struct LogBatch { |
| 105 |
pub records: Vec<Record>, |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
| 110 |
pub struct Finish { |
| 111 |
|
| 112 |
pub exit_code: Option<i32>, |
| 113 |
pub duration_ms: u64, |
| 114 |
pub receipt: Option<Receipt>, |
| 47c1d64d Andy McCall ↶ |
115 |
|
| 116 |
|
| 117 |
#[serde(default, skip_serializing_if = "Option::is_none")] |
| 118 |
pub signed_receipt: Option<String>, |
| e0918b88 Andy McCall |
119 |
|
| 120 |
pub error: Option<String>, |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
pub const MAX_RECORD_TEXT: usize = 16 * 1024; |
| 125 |
|
| 126 |
pub const MAX_RECORDS: usize = 50_000; |