mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-31 05:03:42 +08:00
sunnylink: cleanup unused code in uploader (#1155)
This commit is contained in:
@@ -33,8 +33,6 @@ allow_sleep = bool(os.getenv("UPLOADER_SLEEP", "1"))
|
||||
force_wifi = os.getenv("FORCEWIFI") is not None
|
||||
fake_upload = os.getenv("FAKEUPLOAD") is not None
|
||||
|
||||
OFFROAD_TRANSITION_TIMEOUT = 900. # wait until offroad for 15 minutes before allowing uploads
|
||||
|
||||
|
||||
class FakeRequest:
|
||||
def __init__(self):
|
||||
@@ -252,9 +250,6 @@ def main(exit_event: threading.Event = None) -> None:
|
||||
params = Params()
|
||||
dongle_id = params.get("SunnylinkDongleId")
|
||||
|
||||
offroad_transition_prev = 0.
|
||||
offroad_last = False
|
||||
|
||||
if dongle_id is None:
|
||||
cloudlog.info("uploader missing dongle_id")
|
||||
raise Exception("uploader can't start without dongle id")
|
||||
@@ -265,35 +260,13 @@ def main(exit_event: threading.Event = None) -> None:
|
||||
backoff = 0.1
|
||||
while not exit_event.is_set():
|
||||
sm.update(0)
|
||||
|
||||
offroad = params.get_bool("IsOffroad")
|
||||
t = time.monotonic()
|
||||
if offroad and not offroad_last and t > 300.:
|
||||
offroad_transition_prev = time.monotonic()
|
||||
offroad_last = offroad
|
||||
|
||||
network_type = NetworkType.wifi if force_wifi else sm['deviceState'].networkType
|
||||
network_type = sm['deviceState'].networkType if not force_wifi else NetworkType.wifi
|
||||
if network_type == NetworkType.none:
|
||||
if allow_sleep:
|
||||
time.sleep(60 if offroad else 5)
|
||||
continue
|
||||
|
||||
if params.get_bool("DisableOnroadUploads"):
|
||||
if not offroad or (offroad_transition_prev > 0. and t - offroad_transition_prev < OFFROAD_TRANSITION_TIMEOUT):
|
||||
if not offroad:
|
||||
cloudlog.info("not uploading: onroad uploads disabled")
|
||||
else:
|
||||
wait_minutes = int(OFFROAD_TRANSITION_TIMEOUT / 60)
|
||||
time_left = OFFROAD_TRANSITION_TIMEOUT - (t - offroad_transition_prev)
|
||||
if time_left > 2.0 * 60.0:
|
||||
time_left_str = f"{int(time_left / 60)} minute(s)"
|
||||
else:
|
||||
time_left_str = f"{int(time_left)} seconds(s)"
|
||||
cloudlog.info(f"not uploading: waiting until offroad for {wait_minutes} minutes; {time_left_str} left")
|
||||
if allow_sleep:
|
||||
time.sleep(60)
|
||||
continue
|
||||
|
||||
success = uploader.step(sm['deviceState'].networkType.raw, sm['deviceState'].networkMetered)
|
||||
if success is None:
|
||||
backoff = 60 if offroad else 5
|
||||
@@ -301,7 +274,7 @@ def main(exit_event: threading.Event = None) -> None:
|
||||
backoff = 0.1
|
||||
else:
|
||||
cloudlog.info("upload backoff %r", backoff)
|
||||
backoff = min(backoff * 2, 120)
|
||||
backoff = min(backoff*2, 120)
|
||||
if allow_sleep:
|
||||
time.sleep(backoff + random.uniform(0, backoff))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user