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. 6
      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_AGE = 31 * 24 * 3600 # seconds
WS_FRAME_SIZE = 4096
DEVICE_STATE_UPDATE_INTERVAL = 1.0 # in seconds
NetworkType = log.DeviceState.NetworkType
@ -213,9 +214,10 @@ 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:
# Abort transfer if connection changed to metered after starting upload
# or if athenad is shutting down to re-connect the websocket
if not item.allow_cellular:
if (time.monotonic() - sm.recv_time['deviceState']) > DEVICE_STATE_UPDATE_INTERVAL:
sm.update(0)
metered = sm['deviceState'].networkMetered
if metered and (not item.allow_cellular):
if sm['deviceState'].networkMetered:
raise AbortTransferException
if end_event.is_set():

Loading…
Cancel
Save