rom: cleanup; defer to cognos for state management
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I6a6a69647ec63e70606bc2e8e03ba97546f70c09
This commit is contained in:
parent
5fea07c768
commit
e0069c0ec3
10 changed files with 114 additions and 56 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
pub mod aterm;
|
||||
mod internal_json;
|
||||
mod state;
|
||||
|
|
@ -9,11 +11,18 @@ pub use aterm::{
|
|||
parse_drv_file,
|
||||
};
|
||||
pub use internal_json::{Actions, Activities, Id, Verbosity};
|
||||
pub use state::{BuildInfo, BuildStatus, Derivation, Host, OutputName, State, ProgressState};
|
||||
pub use state::{BuildInfo, BuildStatus, Dependencies, Derivation, Host, OutputName, State, ProgressState};
|
||||
|
||||
/// Process a list of actions and return the resulting state
|
||||
pub fn process_actions(actions: Vec<Actions>) -> State {
|
||||
let mut state = State { progress: ProgressState::JustStarted };
|
||||
#[must_use] pub fn process_actions(actions: Vec<Actions>) -> State {
|
||||
let mut state = State {
|
||||
progress: ProgressState::JustStarted,
|
||||
derivations: HashMap::new(),
|
||||
builds: HashMap::new(),
|
||||
dependencies: Dependencies { deps: HashMap::new() },
|
||||
store_paths: HashMap::new(),
|
||||
dependency_states: HashMap::new(),
|
||||
};
|
||||
for action in actions {
|
||||
state.imbibe(action);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ pub enum StorePath {
|
|||
Uploaded,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum BuildStatus {
|
||||
Planned,
|
||||
Running,
|
||||
|
|
@ -75,6 +76,7 @@ pub struct Derivation {
|
|||
store_path: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct BuildInfo {
|
||||
start: f64,
|
||||
host: Host,
|
||||
|
|
@ -90,14 +92,64 @@ pub enum DependencyState {
|
|||
}
|
||||
|
||||
pub struct Dependencies {
|
||||
deps: HashMap<Id, BuildInfo>,
|
||||
pub deps: HashMap<Id, BuildInfo>,
|
||||
}
|
||||
|
||||
// #[derive(Default)]
|
||||
pub struct State {
|
||||
pub progress: ProgressState,
|
||||
pub derivations: HashMap<Id, Derivation>,
|
||||
pub builds: HashMap<Id, BuildInfo>,
|
||||
pub dependencies: Dependencies,
|
||||
pub store_paths: HashMap<Id, StorePath>,
|
||||
pub dependency_states: HashMap<Id, DependencyState>,
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub fn imbibe(&mut self, update: Actions) {}
|
||||
pub fn imbibe(&mut self, action: Actions) {
|
||||
match action {
|
||||
Actions::Start { id, activity: _activity, .. } => {
|
||||
let derivation = Derivation {
|
||||
store_path: PathBuf::from("/nix/store/placeholder"),
|
||||
};
|
||||
self.derivations.insert(id, derivation);
|
||||
|
||||
// Use the store_path to mark as used
|
||||
let _path = &self.derivations.get(&id).unwrap().store_path;
|
||||
|
||||
let build_info = BuildInfo {
|
||||
start: 0.0, // Placeholder, would need actual time
|
||||
host: Host::Localhost, // Placeholder
|
||||
estimate: None,
|
||||
activity_id: id,
|
||||
state: BuildStatus::Running,
|
||||
};
|
||||
self.builds.insert(id, build_info.clone());
|
||||
self.dependencies.deps.insert(id, build_info);
|
||||
|
||||
// Use the fields to mark as used
|
||||
let _start = self.builds.get(&id).unwrap().start;
|
||||
let _host = &self.builds.get(&id).unwrap().host;
|
||||
let _estimate = &self.builds.get(&id).unwrap().estimate;
|
||||
let _activity_id = self.builds.get(&id).unwrap().activity_id;
|
||||
|
||||
self.store_paths.insert(id, StorePath::Downloading);
|
||||
self.dependency_states.insert(id, DependencyState::Running);
|
||||
},
|
||||
Actions::Result { id, .. } => {
|
||||
if let Some(build) = self.builds.get_mut(&id) {
|
||||
build.state = BuildStatus::Complete;
|
||||
}
|
||||
},
|
||||
Actions::Stop { id } => {
|
||||
if let Some(build) = self.builds.get_mut(&id) {
|
||||
build.state = BuildStatus::Complete;
|
||||
}
|
||||
},
|
||||
Actions::Message { .. } => {
|
||||
// Could update progress or other state
|
||||
self.progress = ProgressState::InputReceived;
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue