Skip to content

Commit

Permalink
Refinement of system tick checking to retry a limited number of times…
Browse files Browse the repository at this point in the history
… and not retry at all once CMDR jas jumped to another system.
  • Loading branch information
aussig committed Jan 24, 2025
1 parent b0f8f74 commit 8109d1f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions bgstally/tick.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,23 @@ def _system_tick_received(self, success: bool, response: Response, request: BGST
if system_address is None:
Debug.logger.warning(f"No system address in system tick callback data")
return
elif system_address != self.bgstally.state.current_system_id:
Debug.logger.warning(f"No longer in same system as system tick callback data")
return

if tick_time < self.tick_time:
# The system tick we've just fetched is older than the current galaxy tick, which must mean it hasn't been updated yet. Trigger another fetch
# after a period of time.
Debug.logger.warning(f"System tick is older than the current galaxy tick - triggering another deferred fetch")
if self.bgstally.ui.frame and request.attempts < 2:
if self.bgstally.ui.frame:
params: dict[str, str] = {'sysAddr': system_address}
self.bgstally.ui.frame.after(10000, partial(self.bgstally.request_manager.queue_request, URL_SYSTEM_TICK_DETECTOR, RequestMethod.POST, params=params, data=request.data, callback=self._system_tick_received, attempts=request.attempts + 1))

if request.attempts < 3:
# Fast refresh initially, in case the only reason the tick hasn't refreshed is because nobody has visited the system and sent over EDDN
self.bgstally.ui.frame.after(10000, partial(self.bgstally.request_manager.queue_request, URL_SYSTEM_TICK_DETECTOR, RequestMethod.POST, params=params, data=request.data, callback=self._system_tick_received, attempts=request.attempts + 1))
else:
# Then slow down to every minute
self.bgstally.ui.frame.after(60000, partial(self.bgstally.request_manager.queue_request, URL_SYSTEM_TICK_DETECTOR, RequestMethod.POST, params=params, data=request.data, callback=self._system_tick_received, attempts=request.attempts + 1))
# Note we fall through here so that even though the tick is old, we still store it

# Store the system tick in the system activity.
Expand Down

0 comments on commit 8109d1f

Please sign in to comment.