Skip to content

Commit

Permalink
chore: state poc
Browse files Browse the repository at this point in the history
  • Loading branch information
MicaiahReid committed Feb 12, 2025
1 parent 10523d6 commit 4c573ce
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 26 deletions.
29 changes: 19 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ path = "src/main.rs"
[dependencies]
surfpool-core = { workspace = true }
# surfpool-core = { version = "0.1" }
# txtx-core = { path = "../../../txtx/crates/txtx-core" }
# txtx-addon-network-svm = { package = "txtx-addon-network-svm", path = "../../../txtx/addons/svm" }
txtx-core = { version = "0.2.2" }
txtx-addon-network-svm = { version = "0.1.3" }
txtx-core = { path = "../../../txtx/crates/txtx-core" }
txtx-addon-network-svm = { package = "txtx-addon-network-svm", path = "../../../txtx/addons/svm" }
# txtx-core = { version = "0.2.2" }
# txtx-addon-network-svm = { version = "0.1.3" }
hiro-system-kit = "0.3.1"
atty = "0.2.13"
ansi_term = "0.12.1"
Expand Down Expand Up @@ -48,4 +48,4 @@ mime_guess = "2.0.4"
[features]
default = ["cli"]
cli = ["clap", "toml", "ctrlc", "hiro-system-kit/log"]
explorer = []
explorer = []
48 changes: 37 additions & 11 deletions crates/cli/src/runbook/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use txtx_core::{
manifest::{file::read_runbooks_from_manifest, WorkspaceManifest},
start_unsupervised_runbook_runloop,
std::StdAddon,
types::RunbookSnapshotContext,
};

pub fn get_addon_by_namespace(namespace: &str) -> Option<Box<dyn Addon>> {
Expand All @@ -21,20 +22,24 @@ pub fn get_addon_by_namespace(namespace: &str) -> Option<Box<dyn Addon>> {
}
None
}

pub const DEFAULT_ENVIRONMENT: &str = "localnet";
pub async fn execute_runbook(
runbook_id: String,
progress_tx: Sender<BlockEvent>,
txtx_manifest_location: FileLocation,
) -> Result<(), String> {
let manifest = WorkspaceManifest::from_location(&txtx_manifest_location)?;
let runbook_selector = vec![runbook_id.to_string()];
let mut runbooks =
read_runbooks_from_manifest(&manifest, &Some("localnet".into()), Some(&runbook_selector))?;
let mut runbooks = read_runbooks_from_manifest(
&manifest,
&Some(DEFAULT_ENVIRONMENT.into()),
Some(&runbook_selector),
)?;
let top_level_inputs_map =
manifest.get_runbook_inputs(&Some("localnet".into()), &vec![], None)?;
manifest.get_runbook_inputs(&Some(DEFAULT_ENVIRONMENT.into()), &vec![], None)?;

let Some((mut runbook, runbook_sources, _state, _smt)) = runbooks.swap_remove(&runbook_id)
let Some((mut runbook, runbook_sources, _state, runbook_state_location)) =
runbooks.swap_remove(&runbook_id)
else {
return Err(format!("Deployment {} not found", runbook_id));
};
Expand All @@ -54,6 +59,32 @@ pub async fn execute_runbook(

runbook.enable_full_execution_mode();

if let Some(state_file_location) = runbook_state_location.clone() {
match state_file_location.load_execution_snapshot(
true,
&runbook.runbook_id.name,
&runbook.top_level_inputs_map.current_top_level_input_name(),
) {
Ok(old_snapshot) => {
let ctx = RunbookSnapshotContext::new();
let execution_context_backups = runbook.backup_execution_contexts();
let new = runbook.simulate_and_snapshot_flows(&old_snapshot).await?;
let consolidated_changes = ctx.diff(old_snapshot, new);

runbook.prepare_flows_for_new_plans(
&consolidated_changes.new_plans_to_add,
execution_context_backups,
);

let _ =
runbook.prepared_flows_for_updated_plans(&consolidated_changes.plans_to_update);
}
Err(e) => {
println!("{} {}", red!("x"), e);
}
}
}

let res = start_unsupervised_runbook_runloop(&mut runbook, &progress_tx).await;
if let Err(diags) = res {
println!("{} Execution aborted", red!("x"));
Expand All @@ -64,12 +95,7 @@ pub async fn execute_runbook(
return Ok(());
}

if let Err(diags) = res {
for diag in diags.iter() {
println!("{} {}", red!("x"), diag);
}
std::process::exit(1);
}
let _ = runbook.write_runbook_state(runbook_state_location)?;

Ok(())
}

0 comments on commit 4c573ce

Please sign in to comment.