MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / reconcile_store_with_backend

Method reconcile_store_with_backend

crates/openshell-server/src/compute/mod.rs:1036–1081  ·  view source on GitHub ↗
(&self, grace_period: Duration)

Source from the content-addressed store, hash-verified

1034 }
1035
1036 async fn reconcile_store_with_backend(&self, grace_period: Duration) -> Result<(), String> {
1037 let sweep_started_at_ms = openshell_core::time::now_ms();
1038 let backend_sandboxes = self
1039 .driver
1040 .list_sandboxes(Request::new(ListSandboxesRequest {}))
1041 .await
1042 .map_err(|e| e.to_string())?
1043 .into_inner()
1044 .sandboxes;
1045 let backend_ids = backend_sandboxes
1046 .iter()
1047 .map(|sandbox| sandbox.id.clone())
1048 .collect::<std::collections::HashSet<_>>();
1049
1050 for sandbox in backend_sandboxes {
1051 self.reconcile_snapshot_sandbox(sandbox, sweep_started_at_ms)
1052 .await?;
1053 }
1054
1055 let records = self
1056 .store
1057 .list(Sandbox::object_type(), 500, 0)
1058 .await
1059 .map_err(|e| e.to_string())?;
1060
1061 let grace_ms = grace_period.as_millis().try_into().unwrap_or(i64::MAX);
1062
1063 for record in records {
1064 let sandbox = match Sandbox::decode(record.payload.as_slice()) {
1065 Ok(sandbox) => sandbox,
1066 Err(err) => {
1067 warn!(error = %err, "Failed to decode sandbox record during reconciliation");
1068 continue;
1069 }
1070 };
1071
1072 if backend_ids.contains(sandbox.object_id()) {
1073 continue;
1074 }
1075
1076 self.prune_missing_sandbox(record, sweep_started_at_ms, grace_ms)
1077 .await?;
1078 }
1079
1080 Ok(())
1081 }
1082
1083 async fn apply_watch_event(&self, event: WatchSandboxesEvent) -> Result<(), String> {
1084 match event.payload {

Calls 7

now_msFunction · 0.85
as_sliceMethod · 0.80
object_idMethod · 0.80
prune_missing_sandboxMethod · 0.80
list_sandboxesMethod · 0.45
listMethod · 0.45

Tested by

no test coverage detected