forked from ghe0/brain-mock
inform daemon about VMs deleted by cron
This commit is contained in:
parent
f0f5edac00
commit
9fa62a1978
18
src/data.rs
18
src/data.rs
@ -192,6 +192,7 @@ impl BrainData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn contracts_cron(&self) {
|
pub fn contracts_cron(&self) {
|
||||||
|
let mut deleted_contracts = Vec::new();
|
||||||
log::debug!("Running contracts cron...");
|
log::debug!("Running contracts cron...");
|
||||||
let mut contracts = self.contracts.write().unwrap();
|
let mut contracts = self.contracts.write().unwrap();
|
||||||
contracts.retain_mut(|c| {
|
contracts.retain_mut(|c| {
|
||||||
@ -213,8 +214,25 @@ impl BrainData {
|
|||||||
);
|
);
|
||||||
c.locked_nano -= nanotokens_to_collect;
|
c.locked_nano -= nanotokens_to_collect;
|
||||||
self.add_nano_to_wallet(&owner_key, nanotokens_to_collect);
|
self.add_nano_to_wallet(&owner_key, nanotokens_to_collect);
|
||||||
|
if c.locked_nano == 0 {
|
||||||
|
deleted_contracts.push((c.uuid.clone(), c.node_pubkey.clone()));
|
||||||
|
}
|
||||||
c.locked_nano > 0
|
c.locked_nano > 0
|
||||||
});
|
});
|
||||||
|
// inform daemons of the deletion of the contracts
|
||||||
|
for (uuid, node_pubkey) in deleted_contracts.iter() {
|
||||||
|
if let Some(daemon_tx) = self.daemon_tx.get(&node_pubkey.clone()) {
|
||||||
|
let msg = grpc::BrainMessage {
|
||||||
|
msg: Some(grpc::brain_message::Msg::DeleteVm(grpc::DeleteVmReq {
|
||||||
|
uuid: uuid.to_string(),
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
let daemon_tx = daemon_tx.clone();
|
||||||
|
tokio::runtime::Runtime::new().unwrap().spawn(async move {
|
||||||
|
let _ = daemon_tx.send(msg).await;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_node(&self, node: Node) {
|
pub fn insert_node(&self, node: Node) {
|
||||||
|
@ -162,11 +162,9 @@ impl BrainCli for BrainCliMock {
|
|||||||
info!("Sending UpdateVMResp: {response:?}");
|
info!("Sending UpdateVMResp: {response:?}");
|
||||||
Ok(Response::new(response))
|
Ok(Response::new(response))
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => Err(Status::unknown(format!(
|
||||||
Err(Status::unknown(
|
"Update VM request failed due to error: {e}"
|
||||||
"Update VM request failed due to error: {e}",
|
))),
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user