@@ -363,7 +363,7 @@ def _async_process_record_update(
363363 elif record .is_expired (now ):
364364 self ._enqueue_callback (ServiceStateChange .Removed , type_ , name )
365365 else :
366- self .reschedule_type (type_ , record .get_expiration_time (_EXPIRE_REFRESH_TIME_PERCENT ))
366+ self .reschedule_type (type_ , now , record .get_expiration_time (_EXPIRE_REFRESH_TIME_PERCENT ))
367367 return
368368
369369 # If its expired or already exists in the cache it cannot be updated.
@@ -431,9 +431,8 @@ def _async_cancel(self) -> None:
431431 self ._cancel_send_timer ()
432432 self .zc .async_remove_listener (self )
433433
434- def _generate_ready_queries (self , first_request : bool ) -> List [DNSOutgoing ]:
434+ def _generate_ready_queries (self , first_request : bool , now : float ) -> List [DNSOutgoing ]:
435435 """Generate the service browser query for any type that is due."""
436- now = current_time_millis ()
437436 ready_types = self .query_scheduler .process_ready_types (now )
438437 if not ready_types :
439438 return []
@@ -448,40 +447,40 @@ def _generate_ready_queries(self, first_request: bool) -> List[DNSOutgoing]:
448447 async def _async_start_query_sender (self ) -> None :
449448 """Start scheduling queries."""
450449 await self .zc .async_wait_for_start ()
451- self ._async_send_ready_queries ()
452- self ._async_schedule_next ()
450+ self ._async_send_ready_queries_schedule_next ()
453451
454452 def _cancel_send_timer (self ) -> None :
455453 """Cancel the next send."""
456454 if self ._next_send_timer :
457455 self ._next_send_timer .cancel ()
458456
459- def reschedule_type (self , type_ : str , next_time : float ) -> None :
457+ def reschedule_type (self , type_ : str , now : float , next_time : float ) -> None :
460458 """Reschedule a type to be refreshed in the future."""
461459 if self .query_scheduler .reschedule_type (type_ , next_time ):
462460 self ._cancel_send_timer ()
463- self ._async_schedule_next ()
464- self ._async_send_ready_queries ()
461+ self ._async_schedule_next (now )
462+ self ._async_send_ready_queries (now )
465463
466- def _async_send_ready_queries (self ) -> None :
464+ def _async_send_ready_queries (self , now : float ) -> None :
467465 """Send any ready queries."""
468- outs = self ._generate_ready_queries (self ._first_request )
466+ outs = self ._generate_ready_queries (self ._first_request , now )
469467 if outs :
470468 self ._first_request = False
471469 for out in outs :
472470 self .zc .async_send (out , addr = self .addr , port = self .port )
473471
474472 def _async_send_ready_queries_schedule_next (self ) -> None :
475- """Send ready queries and schedule next one."""
473+ """Send ready queries and schedule next one checking for done first ."""
476474 if self .done or self .zc .done :
477475 return
478- self ._async_send_ready_queries ()
479- self ._async_schedule_next ()
476+ now = current_time_millis ()
477+ self ._async_send_ready_queries (now )
478+ self ._async_schedule_next (now )
480479
481- def _async_schedule_next (self ) -> None :
480+ def _async_schedule_next (self , now : float ) -> None :
482481 """Scheule the next time."""
483482 assert self .zc .loop is not None
484- delay = millis_to_seconds (self .query_scheduler .millis_to_wait (current_time_millis () ))
483+ delay = millis_to_seconds (self .query_scheduler .millis_to_wait (now ))
485484 self ._next_send_timer = self .zc .loop .call_later (delay , self ._async_send_ready_queries_schedule_next )
486485
487486
0 commit comments