cancelling actions works now

This commit is contained in:
2026-03-10 19:53:20 -05:00
parent 5b45b17fa6
commit 71ea3f34ca
30 changed files with 482 additions and 1071 deletions

View File

@@ -292,6 +292,7 @@ impl EnforcementProcessor {
parent: None, // TODO: Handle workflow parent-child relationships
enforcement: Some(enforcement.id),
executor: None, // Will be assigned during scheduling
worker: None,
status: attune_common::models::enums::ExecutionStatus::Requested,
result: None,
workflow_task: None, // Non-workflow execution

View File

@@ -247,7 +247,7 @@ impl ExecutionManager {
ExecutionRepository::update(pool, child_id, update).await?;
}
if let Some(worker_id) = child.executor {
if let Some(worker_id) = child.worker {
Self::send_cancel_to_worker(publisher, child_id, worker_id).await?;
} else {
warn!(
@@ -423,6 +423,7 @@ impl ExecutionManager {
parent: Some(parent.id), // Link to parent execution
enforcement: parent.enforcement,
executor: None, // Will be assigned during scheduling
worker: None,
status: ExecutionStatus::Requested,
result: None,
workflow_task: None, // Non-workflow execution

View File

@@ -298,6 +298,7 @@ impl RetryManager {
parent: original.parent,
enforcement: original.enforcement,
executor: None, // Will be assigned by scheduler
worker: None,
status: ExecutionStatus::Requested,
result: None,
workflow_task: original.workflow_task.clone(),

View File

@@ -230,9 +230,11 @@ impl ExecutionScheduler {
}
};
// Update execution status to scheduled
// Persist the selected worker so later cancellation requests can be
// routed to the correct per-worker cancel queue.
let mut execution_for_update = execution;
execution_for_update.status = ExecutionStatus::Scheduled;
execution_for_update.worker = Some(worker.id);
ExecutionRepository::update(pool, execution_for_update.id, execution_for_update.into())
.await?;
@@ -529,6 +531,7 @@ impl ExecutionScheduler {
parent: Some(parent_execution.id),
enforcement: parent_execution.enforcement,
executor: None,
worker: None,
status: ExecutionStatus::Requested,
result: None,
workflow_task: Some(workflow_task),
@@ -689,6 +692,7 @@ impl ExecutionScheduler {
parent: Some(parent_execution.id),
enforcement: parent_execution.enforcement,
executor: None,
worker: None,
status: ExecutionStatus::Requested,
result: None,
workflow_task: Some(workflow_task),
@@ -1886,4 +1890,32 @@ mod tests {
serde_json::json!({"parameters": {"n": 5}, "context": {"rule": "test"}})
);
}
#[test]
fn test_scheduling_persists_selected_worker() {
let mut execution = attune_common::models::Execution {
id: 42,
action: Some(7),
action_ref: "core.sleep".to_string(),
config: None,
env_vars: None,
parent: None,
enforcement: None,
executor: None,
worker: None,
status: ExecutionStatus::Requested,
result: None,
started_at: None,
workflow_task: None,
created: Utc::now(),
updated: Utc::now(),
};
execution.status = ExecutionStatus::Scheduled;
execution.worker = Some(99);
let update: UpdateExecutionInput = execution.into();
assert_eq!(update.status, Some(ExecutionStatus::Scheduled));
assert_eq!(update.worker, Some(99));
}
}

View File

@@ -126,6 +126,7 @@ async fn create_test_execution(
parent: None,
enforcement: None,
executor: None,
worker: None,
status,
result: None,
workflow_task: None,

View File

@@ -121,6 +121,7 @@ async fn create_test_execution(
parent: None,
enforcement: None,
executor: None,
worker: None,
status,
result: None,
workflow_task: None,