Public release release-be1f654ae8de
Source commit: be1f654ae8de7d5eeb2005b4e1a05bf1ebf3124f Public tree identity: sha256:ab53679496be4be7d1e02bc00723072774d1a3f87e10cc56558a752f28f6abb1
This commit is contained in:
commit
a6ca9e26dd
210 changed files with 78671 additions and 0 deletions
47
crates/clusterflux-node/src/debug_agent.rs
Normal file
47
crates/clusterflux-node/src/debug_agent.rs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
use std::time::{Duration, Instant};
|
||||
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use crate::coordinator_session::CoordinatorSession;
|
||||
use crate::daemon::{Args, RuntimeTask};
|
||||
use crate::node_identity::signed_node_request_json;
|
||||
|
||||
pub(crate) fn poll_task_cancellation(
|
||||
session: &mut CoordinatorSession,
|
||||
args: &Args,
|
||||
task: &RuntimeTask,
|
||||
node_private_key: &str,
|
||||
) -> Result<bool, Box<dyn std::error::Error>> {
|
||||
let deadline = Instant::now() + Duration::from_millis(args.control_poll_ms);
|
||||
loop {
|
||||
let control = session.request(signed_node_request_json(
|
||||
args,
|
||||
node_private_key,
|
||||
"poll_task_control",
|
||||
json!({
|
||||
"type": "poll_task_control",
|
||||
"tenant": &args.tenant,
|
||||
"project": &args.project,
|
||||
"process": &task.process,
|
||||
"node": &args.node,
|
||||
"task": &task.task,
|
||||
}),
|
||||
)?)?;
|
||||
if control
|
||||
.get("cancel_requested")
|
||||
.and_then(Value::as_bool)
|
||||
.unwrap_or(false)
|
||||
|| control
|
||||
.get("abort_requested")
|
||||
.and_then(Value::as_bool)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
return Ok(true);
|
||||
}
|
||||
let now = Instant::now();
|
||||
if now >= deadline {
|
||||
return Ok(false);
|
||||
}
|
||||
std::thread::sleep((deadline - now).min(Duration::from_millis(100)));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue