mirror of
https://github.com/MoreTore/openpilot.git
synced 2026-08-24 01:23:45 +08:00
updated: reduce frequency of unnecessary updates (#24301)
* updated: reduce frequency of unnecessary updates
* little cleanup
old-commit-hash: e8a9b9ed8c
This commit is contained in:
@@ -62,7 +62,6 @@ function launch {
|
||||
cd $BASEDIR
|
||||
|
||||
echo "Restarting launch script ${LAUNCHER_LOCATION}"
|
||||
unset REQUIRED_NEOS_VERSION
|
||||
unset AGNOS_VERSION
|
||||
exec "${LAUNCHER_LOCATION}"
|
||||
else
|
||||
|
||||
+10
-30
@@ -45,8 +45,6 @@ from selfdrive.version import is_tested_branch
|
||||
LOCK_FILE = os.getenv("UPDATER_LOCK_FILE", "/tmp/safe_staging_overlay.lock")
|
||||
STAGING_ROOT = os.getenv("UPDATER_STAGING_ROOT", "/data/safe_staging")
|
||||
|
||||
NEOSUPDATE_DIR = os.getenv("UPDATER_NEOSUPDATE_DIR", "/data/neoupdate")
|
||||
|
||||
OVERLAY_UPPER = os.path.join(STAGING_ROOT, "upper")
|
||||
OVERLAY_METADATA = os.path.join(STAGING_ROOT, "metadata")
|
||||
OVERLAY_MERGED = os.path.join(STAGING_ROOT, "merged")
|
||||
@@ -180,10 +178,7 @@ def setup_git_options(cwd: str) -> None:
|
||||
def dismount_overlay() -> None:
|
||||
if os.path.ismount(OVERLAY_MERGED):
|
||||
cloudlog.info("unmounting existing overlay")
|
||||
args = ["umount", "-l", OVERLAY_MERGED]
|
||||
if TICI:
|
||||
args = ["sudo"] + args
|
||||
run(args)
|
||||
run(["sudo", "umount", "-l", OVERLAY_MERGED])
|
||||
|
||||
|
||||
def init_overlay() -> None:
|
||||
@@ -206,8 +201,7 @@ def init_overlay() -> None:
|
||||
params.put_bool("UpdateAvailable", False)
|
||||
set_consistent_flag(False)
|
||||
dismount_overlay()
|
||||
if TICI:
|
||||
run(["sudo", "rm", "-rf", STAGING_ROOT])
|
||||
run(["sudo", "rm", "-rf", STAGING_ROOT])
|
||||
if os.path.isdir(STAGING_ROOT):
|
||||
shutil.rmtree(STAGING_ROOT)
|
||||
|
||||
@@ -231,11 +225,8 @@ def init_overlay() -> None:
|
||||
overlay_opts = f"lowerdir={BASEDIR},upperdir={OVERLAY_UPPER},workdir={OVERLAY_METADATA}"
|
||||
|
||||
mount_cmd = ["mount", "-t", "overlay", "-o", overlay_opts, "none", OVERLAY_MERGED]
|
||||
if TICI:
|
||||
run(["sudo"] + mount_cmd)
|
||||
run(["sudo", "chmod", "755", os.path.join(OVERLAY_METADATA, "work")])
|
||||
else:
|
||||
run(mount_cmd)
|
||||
run(["sudo"] + mount_cmd)
|
||||
run(["sudo", "chmod", "755", os.path.join(OVERLAY_METADATA, "work")])
|
||||
|
||||
git_diff = run(["git", "diff"], OVERLAY_MERGED, low_priority=True)
|
||||
params.put("GitDiff", git_diff)
|
||||
@@ -378,19 +369,11 @@ def main() -> None:
|
||||
overlay_init = Path(os.path.join(BASEDIR, ".overlay_init"))
|
||||
overlay_init.unlink(missing_ok=True)
|
||||
|
||||
first_run = True
|
||||
last_fetch_time = 0.0
|
||||
update_failed_count = 0 # TODO: Load from param?
|
||||
|
||||
# Wait for IsOffroad to be set before our first update attempt
|
||||
wait_helper = WaitTimeHelper(proc)
|
||||
wait_helper.sleep(30)
|
||||
|
||||
# Run the update loop
|
||||
# * every 5m, do a lightweight internet/update check
|
||||
# * every 10m, do a full git fetch
|
||||
while not wait_helper.shutdown:
|
||||
update_now = wait_helper.ready_event.is_set()
|
||||
wait_helper.ready_event.clear()
|
||||
|
||||
# Attempt an update
|
||||
@@ -400,19 +383,16 @@ def main() -> None:
|
||||
try:
|
||||
init_overlay()
|
||||
|
||||
# TODO: still needed? skip this and just fetch?
|
||||
# Lightweight internt check
|
||||
internet_ok, update_available = check_for_update()
|
||||
if internet_ok and not update_available:
|
||||
update_failed_count = 0
|
||||
|
||||
# Fetch updates at most every 10 minutes
|
||||
if internet_ok and (update_now or time.monotonic() - last_fetch_time > 60*10):
|
||||
# Fetch update
|
||||
if internet_ok:
|
||||
new_version = fetch_update(wait_helper)
|
||||
update_failed_count = 0
|
||||
last_fetch_time = time.monotonic()
|
||||
|
||||
if first_run and not new_version and os.path.isdir(NEOSUPDATE_DIR):
|
||||
shutil.rmtree(NEOSUPDATE_DIR)
|
||||
first_run = False
|
||||
except subprocess.CalledProcessError as e:
|
||||
cloudlog.event(
|
||||
"update process failed",
|
||||
@@ -433,8 +413,8 @@ def main() -> None:
|
||||
except Exception:
|
||||
cloudlog.exception("uncaught updated exception while setting params, shouldn't happen")
|
||||
|
||||
# TODO: replace this with a good backoff
|
||||
wait_helper.sleep(300)
|
||||
# infrequent attempts if we successfully updated recently
|
||||
wait_helper.sleep(5*60 if update_failed_count > 0 else 90*60)
|
||||
|
||||
dismount_overlay()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user