Skip to content

Commit

Permalink
Stop early when the task is already finished
Browse files Browse the repository at this point in the history
  • Loading branch information
diptanu committed Feb 23, 2025
1 parent 498ef1b commit 9dad0f3
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions server/processor/src/task_creator.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::task;
use std::{sync::Arc, vec};

use anyhow::{anyhow, Result};
Expand All @@ -13,7 +14,7 @@ use data_model::{
TaskOutputsIngestedEvent,
};
use state_store::IndexifyState;
use tracing::{error, info, trace};
use tracing::{error, info, trace, warn};

#[derive(Debug)]
pub struct TaskCreationResult {
Expand Down Expand Up @@ -68,7 +69,8 @@ impl TaskCreator {
error!("error getting task from finished event: {:?}", e);
e
})?;
if task.is_none() {

let Some(task) = task else {
error!(
"task not found for task finished event: {}",
task_finished_event.task_id
Expand All @@ -79,8 +81,7 @@ impl TaskCreator {
&task_finished_event.invocation_id,
None,
));
}
let task = task.ok_or(anyhow!("task not found: {}", task_finished_event.task_id))?;
};

let compute_graph_version = indexify_state
.reader()
Expand Down Expand Up @@ -222,19 +223,26 @@ impl TaskCreator {
e
)
})?;
if invocation_ctx.is_none() {

let Some(mut invocation_ctx ) = invocation_ctx else {
trace!("no invocation ctx, stopping scheduling of child tasks");
return Ok(TaskCreationResult::no_tasks(
&task.namespace,
&task.compute_graph_name,
&task.invocation_id,
None,
));
};

if invocation_ctx.completed {
warn!("invocation already completed, stopping scheduling of child tasks");
return Ok(TaskCreationResult::no_tasks(
&task.namespace,
&task.compute_graph_name,
&task.invocation_id,
None,
));
}
let mut invocation_ctx = invocation_ctx.ok_or(anyhow!(
"invocation context not found for invocation_id {}",
task.invocation_id
))?;

trace!("invocation context: {:?}", invocation_ctx);
invocation_ctx.update_analytics(&task);
Expand Down

0 comments on commit 9dad0f3

Please sign in to comment.