Skip to content

Commit

Permalink
Also clear the schedule cache for recomputation, when the task date h…
Browse files Browse the repository at this point in the history
…as changed.

This happens (without changing the try number) when the task has been cleared.

Later we will also address https://dfinity.atlassian.net/browse/DRE-304 .
This is a very small prelude to that, covering a corner case we were not covering
before.
  • Loading branch information
DFINITYManu committed Oct 10, 2024
1 parent 9e1607f commit 6c44ecd
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions rollout-dashboard/server/src/frontend_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,11 @@ impl From<CyclicDependencyError> for RolloutDataGatherError {
#[derive(Clone, Serialize)]
enum ScheduleCache {
Empty,
Valid(usize, String),
Valid {
try_number: usize,
task_date: DateTime<Utc>,
cached_schedule: String,
},
}

struct RolloutDataCache {
Expand Down Expand Up @@ -635,15 +639,24 @@ impl RolloutApi {
| Some(TaskInstanceState::Scheduled)
| None => rollout.state = min(rollout.state, RolloutState::Preparing),
Some(TaskInstanceState::Success) => {
if let ScheduleCache::Valid(try_number, _) = cache_entry.schedule {
if try_number != task_instance.try_number {
if let ScheduleCache::Valid {
try_number,
task_date,
..
} = cache_entry.schedule
{
if try_number != task_instance.try_number
|| task_date != task_instance.latest_date()
{
info!(target: "frontend_api", "{}: resetting schedule cache", dag_run.dag_run_id);
// Another task run of the same task has executed. We must clear the cache entry.
cache_entry.schedule = ScheduleCache::Empty;
}
}
let schedule_string = match &cache_entry.schedule {
ScheduleCache::Valid(_, s) => s,
ScheduleCache::Valid {
cached_schedule, ..
} => cached_schedule,
ScheduleCache::Empty => {
let value = self
.airflow_api
Expand All @@ -657,10 +670,11 @@ impl RolloutApi {
.await;
let schedule = match value {
Ok(schedule) => {
cache_entry.schedule = ScheduleCache::Valid(
task_instance.try_number,
schedule.value.clone(),
);
cache_entry.schedule = ScheduleCache::Valid {
try_number: task_instance.try_number,
task_date: task_instance.latest_date(),
cached_schedule: schedule.value.clone(),
};
info!(target: "frontend_api", "{}: saving schedule cache", dag_run.dag_run_id);
schedule.value
}
Expand Down

0 comments on commit 6c44ecd

Please sign in to comment.