@@ -222,16 +222,16 @@ pub async fn reconcile(replica: Arc<PostgresPhysicalReplica>, ctx: Arc<Context>)
222222 & ctx. http_client ,
223223 & namespace,
224224 & replica,
225- & switching,
225+ switching,
226226 & conn_info,
227227 & creds_secret_name,
228228 & ctx. metrics ,
229229 )
230230 . await ;
231231
232232 // Recompute next scheduled restore in case schedule changed while restore was in flight
233- if let Some ( schedule) = & replica. spec . schedule {
234- if let Some ( next) = compute_next_scheduled_restore ( schedule) {
233+ if let Some ( schedule) = & replica. spec . schedule
234+ && let Some ( next) = compute_next_scheduled_restore ( schedule) {
235235 update_replica_status_field (
236236 client,
237237 & namespace,
@@ -241,7 +241,6 @@ pub async fn reconcile(replica: Arc<PostgresPhysicalReplica>, ctx: Arc<Context>)
241241 )
242242 . await ?;
243243 }
244- }
245244
246245 return Ok ( Action :: requeue ( Duration :: from_secs ( 10 ) ) ) ;
247246 }
@@ -413,8 +412,8 @@ pub async fn reconcile(replica: Arc<PostgresPhysicalReplica>, ctx: Arc<Context>)
413412
414413 // Whether a restore was created or skipped, advance nextScheduledRestore
415414 // so we don't re-trigger on the next reconciliation.
416- if let Some ( schedule) = & replica. spec . schedule {
417- if let Some ( next) = compute_next_scheduled_restore ( schedule) {
415+ if let Some ( schedule) = & replica. spec . schedule
416+ && let Some ( next) = compute_next_scheduled_restore ( schedule) {
418417 update_replica_status_field (
419418 client,
420419 & namespace,
@@ -424,7 +423,6 @@ pub async fn reconcile(replica: Arc<PostgresPhysicalReplica>, ctx: Arc<Context>)
424423 )
425424 . await ?;
426425 }
427- }
428426 }
429427
430428 // Update phase based on current state
@@ -693,16 +691,15 @@ fn should_trigger_scheduled_restore(replica: &PostgresPhysicalReplica) -> bool {
693691 let status = replica. status . as_ref ( ) ;
694692
695693 // Check minimumTTL
696- if let Some ( last_completed) = status. and_then ( |s| s. last_restore_completed_at . as_ref ( ) ) {
697- if let Ok ( last_completed) = last_completed. parse :: < chrono:: DateTime < Utc > > ( ) {
694+ 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 > > ( ) {
698696 let minimum_ttl =
699697 parse_duration ( & replica. spec . minimum_ttl ) . unwrap_or ( Duration :: from_secs ( 6 * 3600 ) ) ;
700698 let elapsed = Utc :: now ( ) . signed_duration_since ( last_completed) ;
701699 if elapsed. to_std ( ) . unwrap_or_default ( ) < minimum_ttl {
702700 return false ;
703701 }
704702 }
705- }
706703
707704 // Check cron schedule
708705 let Ok ( cron_schedule) = schedule. parse :: < cron:: Schedule > ( ) else {
@@ -717,13 +714,12 @@ fn should_trigger_scheduled_restore(replica: &PostgresPhysicalReplica) -> bool {
717714
718715 let now = Utc :: now ( ) ;
719716
720- if let Some ( next_scheduled) = status. and_then ( |s| s. next_scheduled_restore . as_ref ( ) ) {
721- if let Ok ( next) = next_scheduled. parse :: < chrono:: DateTime < Utc > > ( ) {
717+ 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 > > ( ) {
722719 // Add jitter to the scheduled time
723720 let trigger_at = next + chrono:: Duration :: from_std ( jitter) . unwrap_or_default ( ) ;
724721 return now >= trigger_at;
725722 }
726- }
727723
728724 // Initial seed: nextScheduledRestore not yet set (first reconciliation or field was cleared).
729725 // Fall back to checking whether a cron occurrence falls within a 24h lookback window.
0 commit comments