Skip to content

Commit

Permalink
fix(api): do not limit max retry interval by the main schedule intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
azasypkin committed Jan 25, 2025
1 parent d492c4c commit ff57761
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/scheduler/scheduler_jobs/trackers_run_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,7 @@ mod tests {
} else if !job_meta.is_running {
should_increase_counter = true;
}
} else if attempts_counter >= 3 {
} else if attempts_counter >= 4 {
break;
}

Expand Down
56 changes: 6 additions & 50 deletions src/trackers/api_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,23 +584,21 @@ where
| SchedulerJobRetryStrategy::Exponential { max_interval, .. } = retry_strategy
{
let max_interval = *max_interval;
if max_interval < config.min_retry_interval {
if max_interval < min_interval {
bail!(RetrackError::client(
format!(
"Tracker retry strategy max interval cannot be less than {}, but received {}.",
humantime::format_duration(config.min_retry_interval),
humantime::format_duration(min_interval),
humantime::format_duration(max_interval)
)
));
}

if max_interval > MAX_TRACKER_RETRY_INTERVAL
|| max_interval > min_schedule_interval
{
if max_interval > MAX_TRACKER_RETRY_INTERVAL {
bail!(RetrackError::client(
format!(
"Tracker retry strategy max interval cannot be greater than {}, but received {}.",
humantime::format_duration(MAX_TRACKER_RETRY_INTERVAL.min(min_schedule_interval)),
humantime::format_duration(MAX_TRACKER_RETRY_INTERVAL),
humantime::format_duration(max_interval)
)
));
Expand Down Expand Up @@ -1791,7 +1789,7 @@ mod tests {
tags: tags.clone(),
actions: actions.clone()
}).await),
@r###""Tracker retry strategy max interval cannot be less than 1m, but received 30s.""###
@r###""Tracker retry strategy max interval cannot be less than 2m, but received 30s.""###
);

// Too high max retry interval.
Expand All @@ -1818,29 +1816,6 @@ mod tests {
@r###""Tracker retry strategy max interval cannot be greater than 12h, but received 13h.""###
);

assert_debug_snapshot!(
create_and_fail(api.create_tracker(TrackerCreateParams {
name: "name".to_string(),
enabled: true,
target: target.clone(),
config: TrackerConfig {
job: Some(SchedulerJobConfig {
schedule: "@hourly".to_string(),
retry_strategy: Some(SchedulerJobRetryStrategy::Linear {
initial_interval: Duration::from_secs(120),
increment: Duration::from_secs(10),
max_interval: Duration::from_secs(2 * 3600),
max_attempts: 5,
})
}),
..config.clone()
},
tags: tags.clone(),
actions: actions.clone()
}).await),
@r###""Tracker retry strategy max interval cannot be greater than 1h, but received 2h.""###
);

// Too few requests.
assert_debug_snapshot!(
create_and_fail(api.create_tracker(TrackerCreateParams {
Expand Down Expand Up @@ -2711,7 +2686,7 @@ mod tests {
}),
..Default::default()
}).await),
@r###""Tracker retry strategy max interval cannot be less than 1m, but received 30s.""###
@r###""Tracker retry strategy max interval cannot be less than 2m, but received 30s.""###
);

// Too high max retry interval.
Expand All @@ -2734,25 +2709,6 @@ mod tests {
@r###""Tracker retry strategy max interval cannot be greater than 12h, but received 13h.""###
);

assert_debug_snapshot!(
update_and_fail(trackers.update_tracker(tracker.id, TrackerUpdateParams {
config: Some(TrackerConfig {
job: Some(SchedulerJobConfig {
schedule: "@hourly".to_string(),
retry_strategy: Some(SchedulerJobRetryStrategy::Linear {
initial_interval: Duration::from_secs(120),
increment: Duration::from_secs(10),
max_interval: Duration::from_secs(2 * 3600),
max_attempts: 5,
})
}),
..tracker.config.clone()
}),
..Default::default()
}).await),
@r###""Tracker retry strategy max interval cannot be greater than 1h, but received 2h.""###
);

// Too few requests.
assert_debug_snapshot!(
update_and_fail(trackers.update_tracker(tracker.id, TrackerUpdateParams {
Expand Down

0 comments on commit ff57761

Please sign in to comment.