athenad: optimize network state check in upload callback (#34185)

optimize network state check in upload callback
cam-req-fix
Dean Lee 5 months ago committed by GitHub
parent 6234fbfd40
commit 7ec6a47c1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      system/athena/athenad.py

@ -54,6 +54,7 @@ RETRY_DELAY = 10 # seconds
MAX_RETRY_COUNT = 30 # Try for at most 5 minutes if upload fails immediately MAX_RETRY_COUNT = 30 # Try for at most 5 minutes if upload fails immediately
MAX_AGE = 31 * 24 * 3600 # seconds MAX_AGE = 31 * 24 * 3600 # seconds
WS_FRAME_SIZE = 4096 WS_FRAME_SIZE = 4096
DEVICE_STATE_UPDATE_INTERVAL = 1.0 # in seconds
NetworkType = log.DeviceState.NetworkType NetworkType = log.DeviceState.NetworkType
@ -213,10 +214,11 @@ def retry_upload(tid: int, end_event: threading.Event, increase_count: bool = Tr
def cb(sm, item, tid, end_event: threading.Event, sz: int, cur: int) -> None: def cb(sm, item, tid, end_event: threading.Event, sz: int, cur: int) -> None:
# Abort transfer if connection changed to metered after starting upload # Abort transfer if connection changed to metered after starting upload
# or if athenad is shutting down to re-connect the websocket # or if athenad is shutting down to re-connect the websocket
sm.update(0) if not item.allow_cellular:
metered = sm['deviceState'].networkMetered if (time.monotonic() - sm.recv_time['deviceState']) > DEVICE_STATE_UPDATE_INTERVAL:
if metered and (not item.allow_cellular): sm.update(0)
raise AbortTransferException if sm['deviceState'].networkMetered:
raise AbortTransferException
if end_event.is_set(): if end_event.is_set():
raise AbortTransferException raise AbortTransferException

Loading…
Cancel
Save