Updated: fix setting update time (#29004)

* sleep in launch

* set time loop

* log

* try longer delay + logging

* try longer delay + logging

* fix order of update

* fix order of update

* fix order of update

* revert panda

* also don't show connectivity error without failed checks

* slightly cleanup updated

* fix type error

* init overlay first

* minimal diff

* comment

* minimal diff

* minimal diff

* explicit parameter to make it clear

* explicit parameter to make it clear

* use finally

* dont use finally

* PR cleanup

* reduce frequency

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>

---------

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
old-commit-hash: ce2708fa67
This commit is contained in:
Justin Newberry 2023-07-18 21:26:05 -07:00 committed by GitHub
parent 5f8e1afc88
commit f465c3f3ac
2 changed files with 21 additions and 10 deletions

View File

@ -1,3 +1,6 @@
import datetime
MIN_DATE = datetime.datetime(year=2023, month=6, day=1)
def system_time_valid():
return datetime.datetime.now() > MIN_DATE

View File

@ -16,6 +16,7 @@ from markdown_it import MarkdownIt
from common.basedir import BASEDIR
from common.params import Params
from common.time import system_time_valid
from system.hardware import AGNOS, HARDWARE
from system.swaglog import cloudlog
from selfdrive.controls.lib.alertmanager import set_offroad_alert
@ -256,14 +257,14 @@ class Updater:
def get_commit_hash(self, path: str = OVERLAY_MERGED) -> str:
return run(["git", "rev-parse", "HEAD"], path).rstrip()
def set_params(self, failed_count: int, exception: Optional[str]) -> None:
def set_params(self, update_success: bool, failed_count: int, exception: Optional[str]) -> None:
self.params.put("UpdateFailedCount", str(failed_count))
self.params.put_bool("UpdaterFetchAvailable", self.update_available)
self.params.put("UpdaterAvailableBranches", ','.join(self.branches.keys()))
last_update = datetime.datetime.utcnow()
if failed_count == 0:
if update_success:
t = last_update.isoformat()
self.params.put("LastUpdateTime", t.encode('utf8'))
else:
@ -317,11 +318,12 @@ class Updater:
else:
extra_text = exception
set_offroad_alert("Offroad_UpdateFailed", True, extra_text=extra_text)
elif dt.days > DAYS_NO_CONNECTIVITY_MAX and failed_count > 1:
set_offroad_alert("Offroad_ConnectivityNeeded", True)
elif dt.days > DAYS_NO_CONNECTIVITY_PROMPT:
remaining = max(DAYS_NO_CONNECTIVITY_MAX - dt.days, 1)
set_offroad_alert("Offroad_ConnectivityNeededPrompt", True, extra_text=f"{remaining} day{'' if remaining == 1 else 's'}.")
elif failed_count > 0:
if dt.days > DAYS_NO_CONNECTIVITY_MAX:
set_offroad_alert("Offroad_ConnectivityNeeded", True)
elif dt.days > DAYS_NO_CONNECTIVITY_PROMPT:
remaining = max(DAYS_NO_CONNECTIVITY_MAX - dt.days, 1)
set_offroad_alert("Offroad_ConnectivityNeededPrompt", True, extra_text=f"{remaining} day{'' if remaining == 1 else 's'}.")
def check_for_update(self) -> None:
cloudlog.info("checking for updates")
@ -417,7 +419,7 @@ def main() -> None:
params.put("InstallDate", t.encode('utf8'))
updater = Updater()
update_failed_count = 0 # TODO: Load from param?
update_failed_count = 0 # TODO: Load from param?
# no fetch on the first time
wait_helper = WaitTimeHelper()
@ -437,7 +439,12 @@ def main() -> None:
init_overlay()
# ensure we have some params written soon after startup
updater.set_params(update_failed_count, exception)
updater.set_params(False, update_failed_count, exception)
if not system_time_valid():
wait_helper.sleep(60)
continue
update_failed_count += 1
# check for update
@ -466,7 +473,8 @@ def main() -> None:
try:
params.put("UpdaterState", "idle")
updater.set_params(update_failed_count, exception)
update_successful = (update_failed_count == 0)
updater.set_params(update_successful, update_failed_count, exception)
except Exception:
cloudlog.exception("uncaught updated exception while setting params, shouldn't happen")