@@ -304,18 +304,18 @@ impl ProjectRef<'_> {
304304 ) ;
305305 }
306306
307- self . private . complete_fetch ( & fetch, now) ;
308-
309- // Keep the old state around if the current fetch is pending.
310- // It may still be useful to callers.
307+ // Update private and shared state with the new data.
308+ let expiry = self . private . complete_fetch ( & fetch, now, config) ;
311309 match fetch. state {
310+ // Keep the old state around if the current fetch is pending.
311+ // It may still be useful to callers.
312312 SourceProjectState :: New ( state) if !state. is_pending ( ) => {
313313 self . shared . set_project_state ( state) ;
314314 }
315315 _ => { }
316316 }
317317
318- self . private . expiry_time ( config )
318+ expiry
319319 }
320320}
321321
@@ -581,19 +581,6 @@ impl PrivateProjectState {
581581 }
582582 }
583583
584- /// Returns the expiry time of the time project state.
585- ///
586- /// `None` if there is currently a fetch pending or in progress.
587- fn expiry_time ( & self , config : & Config ) -> Option < ExpiryTime > {
588- match & self . state {
589- FetchState :: Complete { when } => {
590- debug_assert_eq ! ( Some ( when. 0 ) , self . last_fetch) ;
591- Some ( when. expiry_time ( config) )
592- }
593- _ => None ,
594- }
595- }
596-
597584 fn try_begin_fetch ( & mut self , now : Instant , config : & Config ) -> Option < Fetch > {
598585 let ( initiated, when) = match & self . state {
599586 FetchState :: InProgress => {
@@ -610,15 +597,19 @@ impl PrivateProjectState {
610597 // Schedule a new fetch, even if there is a backoff, it will just be sleeping for a while.
611598 ( initiated. unwrap_or ( now) , * next_fetch_attempt)
612599 }
613- FetchState :: Complete { when : last_fetch } => {
614- if last_fetch. check_expiry ( now, config) . is_fresh ( ) {
600+ FetchState :: Complete { when } => {
601+ // Sanity check to make sure timestamps do not drift.
602+ debug_assert_eq ! ( Some ( when. 0 ) , self . last_fetch) ;
603+
604+ if when. check_expiry ( now, config) . is_fresh ( ) {
615605 // The current state is up to date, no need to start another fetch.
616606 relay_log:: trace!(
617607 tags. project_key = self . project_key. as_str( ) ,
618608 "project fetch skipped, already up to date"
619609 ) ;
620610 return None ;
621611 }
612+
622613 ( now, None )
623614 }
624615 } ;
@@ -642,7 +633,12 @@ impl PrivateProjectState {
642633 } )
643634 }
644635
645- fn complete_fetch ( & mut self , fetch : & CompletedFetch , now : Instant ) {
636+ fn complete_fetch (
637+ & mut self ,
638+ fetch : & CompletedFetch ,
639+ now : Instant ,
640+ config : & Config ,
641+ ) -> Option < ExpiryTime > {
646642 debug_assert ! (
647643 matches!( self . state, FetchState :: InProgress ) ,
648644 "fetch completed while there was no current fetch registered"
@@ -662,16 +658,20 @@ impl PrivateProjectState {
662658 tags. project_key = & self . project_key. as_str( ) ,
663659 "project state fetch completed but still pending"
664660 ) ;
661+
662+ None
665663 } else {
666664 relay_log:: trace!(
667665 tags. project_key = & self . project_key. as_str( ) ,
668666 "project state fetch completed with non-pending config"
669667 ) ;
668+
670669 self . backoff . reset ( ) ;
671670 self . last_fetch = Some ( now) ;
672- self . state = FetchState :: Complete {
673- when : LastFetch ( now) ,
674- } ;
671+
672+ let when = LastFetch ( now) ;
673+ self . state = FetchState :: Complete { when } ;
674+ Some ( when. expiry_time ( config) )
675675 }
676676 }
677677}
0 commit comments