Skip to main content

pfx_run/
job.rs

1use std::path::Path;
2
3pub const TOOL: &str = "pfx";
4pub const HD_DETAIL: &str = "hd: ";
5pub const ASSETS_DETAIL: &str = "assets: ";
6
7pub mod stages {
8    pub const BUILD: &str = "build";
9    pub const TRACE: &str = "trace";
10    pub const TRACE_PROP: &str = "trace prop";
11    pub const TRACE_REFLECTION: &str = "trace reflection";
12    pub const DERIVE: &str = "derive";
13    pub const MASTER: &str = "master";
14    pub const ENCODE: &str = "encode";
15    pub const ARCHIVE: &str = "archive";
16
17    pub const APP_STILL: &[&str] = &[BUILD, TRACE, DERIVE, ARCHIVE];
18    pub const APP_CLIP: &[&str] = &[BUILD, TRACE, MASTER, ENCODE, ARCHIVE];
19    pub const APP_ENCODE: &[&str] = &[ENCODE, ARCHIVE];
20    pub const ASSET_STILL: &[&str] = &[TRACE, ARCHIVE];
21    pub const ASSET_CLIP: &[&str] = &[TRACE, MASTER, ENCODE, ARCHIVE];
22    pub const ASSET_ENCODE: &[&str] = &[ENCODE, ARCHIVE];
23    pub const ARCHIVE_RETRY: &[&str] = &[ARCHIVE];
24}
25
26pub struct Job;
27
28impl Job {
29    pub fn disabled() -> Job {
30        Job
31    }
32
33    pub fn start(_tool: &str, _app: Option<&str>, _label: &str) -> Job {
34        Job
35    }
36
37    pub fn plan(&mut self, _names: &[&'static str]) {}
38
39    pub fn archiving(&mut self, _runs: bool) {}
40
41    pub fn detail(&mut self, _detail: String) {}
42
43    pub fn device(&mut self, _device: &str) {}
44
45    pub fn out(&mut self, _dir: &Path) {}
46
47    pub fn stage(&self, _name: &str, _total: Option<u64>, _unit: &str) {}
48
49    pub fn note(&self, _note: &str) {}
50
51    pub fn progress(&self, _done: u64) {}
52
53    pub fn rendered(&self) {}
54
55    pub fn pgpu(&self, _pid: Option<u32>) {}
56
57    pub fn end<T>(self, result: Result<T, String>) -> Result<T, String> {
58        result
59    }
60}
61
62#[cfg(test)]
63mod tests {
64    use super::{ASSETS_DETAIL, HD_DETAIL, TOOL, stages};
65
66    #[test]
67    fn the_plans_use_only_the_stage_names_the_renderers_call() {
68        let known = [
69            stages::BUILD,
70            stages::TRACE,
71            stages::TRACE_PROP,
72            stages::TRACE_REFLECTION,
73            stages::DERIVE,
74            stages::MASTER,
75            stages::ENCODE,
76            stages::ARCHIVE,
77        ];
78        for plan in [
79            stages::APP_STILL,
80            stages::APP_CLIP,
81            stages::APP_ENCODE,
82            stages::ASSET_STILL,
83            stages::ASSET_CLIP,
84            stages::ASSET_ENCODE,
85            stages::ARCHIVE_RETRY,
86        ] {
87            assert!(plan.iter().all(|name| known.contains(name)));
88            let mut seen = plan.to_vec();
89            seen.dedup();
90            assert_eq!(seen, plan);
91        }
92    }
93
94    #[test]
95    fn the_job_names_pfx_and_the_detail_prefixes_ptop_keys_on() {
96        assert_eq!(TOOL, "pfx");
97        assert_eq!(HD_DETAIL, "hd: ");
98        assert_eq!(ASSETS_DETAIL, "assets: ");
99    }
100}