Skip to content

Commit b644fe2

Browse files
committed
more clippy
1 parent d3a783b commit b644fe2

3 files changed

Lines changed: 81 additions & 70 deletions

File tree

src/controllers/replica.rs

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,17 @@ pub async fn reconcile(replica: Arc<PostgresPhysicalReplica>, ctx: Arc<Context>)
231231

232232
// Recompute next scheduled restore in case schedule changed while restore was in flight
233233
if let Some(schedule) = &replica.spec.schedule
234-
&& let Some(next) = compute_next_scheduled_restore(schedule) {
235-
update_replica_status_field(
236-
client,
237-
&namespace,
238-
&name,
239-
"nextScheduledRestore",
240-
&next.to_rfc3339(),
241-
)
242-
.await?;
243-
}
234+
&& let Some(next) = compute_next_scheduled_restore(schedule)
235+
{
236+
update_replica_status_field(
237+
client,
238+
&namespace,
239+
&name,
240+
"nextScheduledRestore",
241+
&next.to_rfc3339(),
242+
)
243+
.await?;
244+
}
244245

245246
return Ok(Action::requeue(Duration::from_secs(10)));
246247
}
@@ -413,16 +414,17 @@ pub async fn reconcile(replica: Arc<PostgresPhysicalReplica>, ctx: Arc<Context>)
413414
// Whether a restore was created or skipped, advance nextScheduledRestore
414415
// so we don't re-trigger on the next reconciliation.
415416
if let Some(schedule) = &replica.spec.schedule
416-
&& let Some(next) = compute_next_scheduled_restore(schedule) {
417-
update_replica_status_field(
418-
client,
419-
&namespace,
420-
&name,
421-
"nextScheduledRestore",
422-
&next.to_rfc3339(),
423-
)
424-
.await?;
425-
}
417+
&& let Some(next) = compute_next_scheduled_restore(schedule)
418+
{
419+
update_replica_status_field(
420+
client,
421+
&namespace,
422+
&name,
423+
"nextScheduledRestore",
424+
&next.to_rfc3339(),
425+
)
426+
.await?;
427+
}
426428
}
427429

428430
// Update phase based on current state
@@ -692,14 +694,15 @@ fn should_trigger_scheduled_restore(replica: &PostgresPhysicalReplica) -> bool {
692694

693695
// Check minimumTTL
694696
if let Some(last_completed) = status.and_then(|s| s.last_restore_completed_at.as_ref())
695-
&& let Ok(last_completed) = last_completed.parse::<chrono::DateTime<Utc>>() {
696-
let minimum_ttl =
697-
parse_duration(&replica.spec.minimum_ttl).unwrap_or(Duration::from_secs(6 * 3600));
698-
let elapsed = Utc::now().signed_duration_since(last_completed);
699-
if elapsed.to_std().unwrap_or_default() < minimum_ttl {
700-
return false;
701-
}
697+
&& let Ok(last_completed) = last_completed.parse::<chrono::DateTime<Utc>>()
698+
{
699+
let minimum_ttl =
700+
parse_duration(&replica.spec.minimum_ttl).unwrap_or(Duration::from_secs(6 * 3600));
701+
let elapsed = Utc::now().signed_duration_since(last_completed);
702+
if elapsed.to_std().unwrap_or_default() < minimum_ttl {
703+
return false;
702704
}
705+
}
703706

704707
// Check cron schedule
705708
let Ok(cron_schedule) = schedule.parse::<cron::Schedule>() else {
@@ -715,20 +718,22 @@ fn should_trigger_scheduled_restore(replica: &PostgresPhysicalReplica) -> bool {
715718
let now = Utc::now();
716719

717720
if let Some(next_scheduled) = status.and_then(|s| s.next_scheduled_restore.as_ref())
718-
&& let Ok(next) = next_scheduled.parse::<chrono::DateTime<Utc>>() {
719-
// Add jitter to the scheduled time
720-
let trigger_at = next + chrono::Duration::from_std(jitter).unwrap_or_default();
721-
return now >= trigger_at;
722-
}
721+
&& let Ok(next) = next_scheduled.parse::<chrono::DateTime<Utc>>()
722+
{
723+
// Add jitter to the scheduled time
724+
let trigger_at = next + chrono::Duration::from_std(jitter).unwrap_or_default();
725+
return now >= trigger_at;
726+
}
723727

724728
// Initial seed: nextScheduledRestore not yet set (first reconciliation or field was cleared).
725729
// Fall back to checking whether a cron occurrence falls within a 24h lookback window.
726730
let jittered_now = now - chrono::Duration::from_std(jitter).unwrap_or_default();
727-
for prev in cron_schedule.after(&(jittered_now - chrono::Duration::hours(24))) {
728-
if prev <= now {
729-
return true;
730-
}
731-
break;
731+
if let Some(prev) = cron_schedule
732+
.after(&(jittered_now - chrono::Duration::hours(24)))
733+
.next()
734+
&& prev <= now
735+
{
736+
return true;
732737
}
733738

734739
false
@@ -1032,6 +1037,10 @@ async fn update_restore_activated_at(
10321037
Ok(())
10331038
}
10341039

1040+
#[expect(
1041+
clippy::too_many_arguments,
1042+
reason = "notification dispatch needs all these context params"
1043+
)]
10351044
async fn send_restore_notifications(
10361045
client: &Client,
10371046
http_client: &reqwest::Client,

src/controllers/restore.rs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -350,39 +350,40 @@ async fn reconcile_ready(
350350

351351
// Check for timeout (10 minutes)
352352
if let Some(created_at) = restore.status.as_ref().and_then(|s| s.restored_at.as_ref())
353-
&& let Ok(created) = created_at.parse::<chrono::DateTime<Utc>>() {
354-
let elapsed = Utc::now().signed_duration_since(created);
355-
if elapsed > chrono::Duration::minutes(10) {
356-
warn!(
357-
restore = name,
358-
"deployment not ready after 10 minutes, marking as Failed"
359-
);
360-
update_restore_status(
361-
client,
362-
namespace,
363-
name,
364-
serde_json::json!({
365-
"phase": "Failed",
366-
}),
367-
)
368-
.await?;
369-
370-
let mut queue = ctx.restore_queue.write().await;
371-
queue.remove(replica_name);
372-
let promoted = queue.try_promote(ctx.max_concurrent_restores());
373-
ctx.metrics.active_restores.set(queue.active.len() as i64);
374-
ctx.metrics.queue_depth.set(queue.pending.len() as i64);
375-
drop(queue);
376-
377-
if let Some(promoted_name) = promoted {
378-
info!(promoted = %promoted_name, "promoted queued restore after timeout failure");
379-
}
353+
&& let Ok(created) = created_at.parse::<chrono::DateTime<Utc>>()
354+
{
355+
let elapsed = Utc::now().signed_duration_since(created);
356+
if elapsed > chrono::Duration::minutes(10) {
357+
warn!(
358+
restore = name,
359+
"deployment not ready after 10 minutes, marking as Failed"
360+
);
361+
update_restore_status(
362+
client,
363+
namespace,
364+
name,
365+
serde_json::json!({
366+
"phase": "Failed",
367+
}),
368+
)
369+
.await?;
370+
371+
let mut queue = ctx.restore_queue.write().await;
372+
queue.remove(replica_name);
373+
let promoted = queue.try_promote(ctx.max_concurrent_restores());
374+
ctx.metrics.active_restores.set(queue.active.len() as i64);
375+
ctx.metrics.queue_depth.set(queue.pending.len() as i64);
376+
drop(queue);
377+
378+
if let Some(promoted_name) = promoted {
379+
info!(promoted = %promoted_name, "promoted queued restore after timeout failure");
380+
}
380381

381-
ctx.metrics.restores_failed_total.inc();
382+
ctx.metrics.restores_failed_total.inc();
382383

383-
return Ok(Action::requeue(Duration::from_secs(300)));
384-
}
384+
return Ok(Action::requeue(Duration::from_secs(300)));
385385
}
386+
}
386387

387388
return Ok(Action::requeue(Duration::from_secs(10)));
388389
}

src/kopia.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@ pub fn filter_snapshots(snapshots: &[Snapshot], filter: Option<&SnapshotFilter>)
111111

112112
// Host pattern filtering
113113
if let Some(pattern) = &filter.host_pattern
114-
&& !glob_matches(pattern, &snap.hostname) {
115-
return false;
116-
}
114+
&& !glob_matches(pattern, &snap.hostname)
115+
{
116+
return false;
117+
}
117118

118119
true
119120
})

0 commit comments

Comments
 (0)