improve updated responsiveness (#1973)

old-commit-hash: 88c67e7e9f
commatwo_master
Adeeb Shihadeh 5 years ago committed by GitHub
parent 7996e51de3
commit 0b64a13bc9
  1. 80
      selfdrive/updated.py

@ -76,12 +76,12 @@ class WaitTimeHelper:
self.ready_event.set() self.ready_event.set()
def wait_between_updates(ready_event): def wait_between_updates(ready_event, t=60*10):
ready_event.clear() ready_event.clear()
if SHORT: if SHORT:
ready_event.wait(timeout=10) ready_event.wait(timeout=10)
else: else:
ready_event.wait(timeout=60 * 10) ready_event.wait(timeout=t)
def link(src, dest): def link(src, dest):
@ -341,50 +341,52 @@ def main():
time.sleep(30) time.sleep(30)
wait_helper = WaitTimeHelper() wait_helper = WaitTimeHelper()
while True: while not wait_helper.shutdown:
update_failed_count += 1 update_failed_count += 1
# Check for internet every 30s
time_wrong = datetime.datetime.utcnow().year < 2019 time_wrong = datetime.datetime.utcnow().year < 2019
ping_failed = subprocess.call(["ping", "-W", "4", "-c", "1", "8.8.8.8"]) ping_failed = subprocess.call(["ping", "-W", "4", "-c", "1", "8.8.8.8"])
if ping_failed or time_wrong:
wait_between_updates(wait_helper.ready_event, t=30)
continue
# Wait until we have a valid datetime to initialize the overlay # Attempt an update
if not (ping_failed or time_wrong): try:
try: # If the git directory has modifcations after we created the overlay
# If the git directory has modifcations after we created the overlay # we need to recreate the overlay
# we need to recreate the overlay if overlay_init_done:
if overlay_init_done: overlay_init_fn = os.path.join(BASEDIR, ".overlay_init")
overlay_init_fn = os.path.join(BASEDIR, ".overlay_init") git_dir_path = os.path.join(BASEDIR, ".git")
git_dir_path = os.path.join(BASEDIR, ".git") new_files = run(["find", git_dir_path, "-newer", overlay_init_fn])
new_files = run(["find", git_dir_path, "-newer", overlay_init_fn])
if len(new_files.splitlines()):
if len(new_files.splitlines()): cloudlog.info(".git directory changed, recreating overlay")
cloudlog.info(".git directory changed, recreating overlay") overlay_init_done = False
overlay_init_done = False
if not overlay_init_done:
if not overlay_init_done: init_ovfs()
init_ovfs() overlay_init_done = True
overlay_init_done = True
if params.get("IsOffroad") == b"1":
if params.get("IsOffroad") == b"1": attempt_update()
attempt_update() update_failed_count = 0
update_failed_count = 0 else:
else: cloudlog.info("not running updater, openpilot running")
cloudlog.info("not running updater, openpilot running")
except subprocess.CalledProcessError as e:
except subprocess.CalledProcessError as e: cloudlog.event(
cloudlog.event( "update process failed",
"update process failed", cmd=e.cmd,
cmd=e.cmd, output=e.output,
output=e.output, returncode=e.returncode
returncode=e.returncode )
) overlay_init_done = False
overlay_init_done = False except Exception:
except Exception: cloudlog.exception("uncaught updated exception, shouldn't happen")
cloudlog.exception("uncaught updated exception, shouldn't happen")
params.put("UpdateFailedCount", str(update_failed_count)) params.put("UpdateFailedCount", str(update_failed_count))
wait_between_updates(wait_helper.ready_event) wait_between_updates(wait_helper.ready_event)
if wait_helper.shutdown:
break
# We've been signaled to shut down # We've been signaled to shut down
dismount_ovfs() dismount_ovfs()

Loading…
Cancel
Save