Skip to content

Commit

Permalink
Merge branch 'branches/rudder/8.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
amousset committed Oct 28, 2024
2 parents 93d0f89 + 41a9b32 commit f602c33
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions policies/module-types/system-updates/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rudder_module_type::Outcome;

#[derive(PartialEq, Debug, Clone, Copy)]
enum Action {
Schedule(DateTime<Utc>),
Schedule(DateTime<Utc>, bool),
Update,
PostUpdate,
}
Expand Down Expand Up @@ -75,9 +75,15 @@ impl Runner {

fn execute(&mut self, action: Action) -> Result<Continuation> {
match action {
Action::Schedule(datetime) => {
do_schedule(&self.parameters, &mut self.db, datetime)?;
Ok(Continuation::Continue)
Action::Schedule(datetime, is_started) => {
let outcome = do_schedule(&self.parameters, &mut self.db, datetime)?;
if is_started {
// If already in the window, don't send the schedule but
// continue instead.
Ok(Continuation::Continue)
} else {
Ok(Continuation::Stop(outcome))
}
}
Action::Update => {
let reboot_needed =
Expand Down Expand Up @@ -112,12 +118,13 @@ impl Runner {
scheduler::splayed_start(s.start, s.end, s.agent_frequency, s.node_id.as_str())?
}
};
let is_started = now >= schedule_datetime;

match current_status {
None => Ok(Some(Action::Schedule(schedule_datetime))),
None => Ok(Some(Action::Schedule(schedule_datetime, is_started))),
Some(s) => match s {
UpdateStatus::ScheduledUpdate => {
if now >= schedule_datetime {
if is_started {
Ok(Some(Action::Update))
} else {
Ok(None)
Expand Down Expand Up @@ -241,7 +248,7 @@ mod tests {
pub fn initial_state_with_immediate_schedule_should_return_schedule() {
let parameters = default_runner_parameters();
match test_runner(false, parameters).decide(None).unwrap() {
Some(Action::Schedule(_)) => {}
Some(Action::Schedule(_, true)) => {}
_ => panic!(),
}
}
Expand All @@ -253,7 +260,7 @@ mod tests {
..default_runner_parameters()
};
match test_runner(false, parameters).decide(None).unwrap() {
Some(Action::Schedule(_)) => {}
Some(Action::Schedule(_, false)) => {}
_ => panic!(),
}
}
Expand Down Expand Up @@ -326,7 +333,7 @@ mod tests {
};
assert_eq!(
test_runner(false, parameters).run().unwrap(),
Outcome::Success(None)
Outcome::Repaired("Schedule has been sent".to_string())
);
}

Expand Down

0 comments on commit f602c33

Please sign in to comment.