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