runnerd_core/api/
results.rs1use super::{Paused, RemovedRecords, Resize};
6use crate::config::ByteSize;
7
8pub fn force_pause_consequence(jobs: usize) -> &'static str {
11 if jobs == 1 {
12 "cancels its run on GitHub and removes its runner"
13 } else {
14 "cancels their runs on GitHub and removes their runners"
15 }
16}
17
18impl Paused {
19 pub fn line(&self, target: &str) -> String {
22 if self.stopped.is_empty() {
23 return format!("{target} paused: it gets no new runners");
24 }
25 let stopped: Vec<String> = self.stopped.iter().map(ToString::to_string).collect();
26 format!("{target} paused; stopped {}", stopped.join(", "))
27 }
28}
29
30pub fn reseed_requested(profile: &str) -> String {
32 format!("{profile}: reseed requested; it runs once the profile's slots are free")
33}
34
35pub fn reseeded(profile: &str, error: Option<&str>) -> String {
37 match error {
38 Some(error) => format!("{profile}: reseed failed: {error}"),
39 None => format!("{profile}: reseeded"),
40 }
41}
42
43pub fn reseed_outcome(output: &str) -> &str {
46 let mut lines = output.trim().lines();
47 lines
48 .clone()
49 .find(|line| line.contains("over from the image"))
50 .or_else(|| lines.next_back())
51 .unwrap_or_default()
52}
53
54impl RemovedRecords {
55 pub fn line(&self) -> String {
57 match self.jobs.len() {
58 0 => "no record removed".to_owned(),
59 1 => format!("removed 1 record, {} freed", ByteSize(self.bytes)),
60 count => format!("removed {count} records, {} freed", ByteSize(self.bytes)),
61 }
62 }
63}
64
65impl Resize {
66 pub fn written_line(&self, profile: &str) -> String {
69 let cpus = self
70 .cpus
71 .map(|cpus| format!(", {cpus} cpus"))
72 .unwrap_or_default();
73 format!(
74 "{profile}: memory {}, {} slots{cpus} written; the daemon runs with them",
75 ByteSize(self.memory),
76 self.slots
77 )
78 }
79}
80
81#[cfg(test)]
82mod tests;