mirror of https://github.com/commaai/openpilot.git
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:
parent
5f8e1afc88
commit
f465c3f3ac
|
@ -1,3 +1,6 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
MIN_DATE = datetime.datetime(year=2023, month=6, day=1)
|
MIN_DATE = datetime.datetime(year=2023, month=6, day=1)
|
||||||
|
|
||||||
|
def system_time_valid():
|
||||||
|
return datetime.datetime.now() > MIN_DATE
|
|
@ -16,6 +16,7 @@ from markdown_it import MarkdownIt
|
||||||
|
|
||||||
from common.basedir import BASEDIR
|
from common.basedir import BASEDIR
|
||||||
from common.params import Params
|
from common.params import Params
|
||||||
|
from common.time import system_time_valid
|
||||||
from system.hardware import AGNOS, HARDWARE
|
from system.hardware import AGNOS, HARDWARE
|
||||||
from system.swaglog import cloudlog
|
from system.swaglog import cloudlog
|
||||||
from selfdrive.controls.lib.alertmanager import set_offroad_alert
|
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:
|
def get_commit_hash(self, path: str = OVERLAY_MERGED) -> str:
|
||||||
return run(["git", "rev-parse", "HEAD"], path).rstrip()
|
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("UpdateFailedCount", str(failed_count))
|
||||||
|
|
||||||
self.params.put_bool("UpdaterFetchAvailable", self.update_available)
|
self.params.put_bool("UpdaterFetchAvailable", self.update_available)
|
||||||
self.params.put("UpdaterAvailableBranches", ','.join(self.branches.keys()))
|
self.params.put("UpdaterAvailableBranches", ','.join(self.branches.keys()))
|
||||||
|
|
||||||
last_update = datetime.datetime.utcnow()
|
last_update = datetime.datetime.utcnow()
|
||||||
if failed_count == 0:
|
if update_success:
|
||||||
t = last_update.isoformat()
|
t = last_update.isoformat()
|
||||||
self.params.put("LastUpdateTime", t.encode('utf8'))
|
self.params.put("LastUpdateTime", t.encode('utf8'))
|
||||||
else:
|
else:
|
||||||
|
@ -317,11 +318,12 @@ class Updater:
|
||||||
else:
|
else:
|
||||||
extra_text = exception
|
extra_text = exception
|
||||||
set_offroad_alert("Offroad_UpdateFailed", True, extra_text=extra_text)
|
set_offroad_alert("Offroad_UpdateFailed", True, extra_text=extra_text)
|
||||||
elif dt.days > DAYS_NO_CONNECTIVITY_MAX and failed_count > 1:
|
elif failed_count > 0:
|
||||||
set_offroad_alert("Offroad_ConnectivityNeeded", True)
|
if dt.days > DAYS_NO_CONNECTIVITY_MAX:
|
||||||
elif dt.days > DAYS_NO_CONNECTIVITY_PROMPT:
|
set_offroad_alert("Offroad_ConnectivityNeeded", True)
|
||||||
remaining = max(DAYS_NO_CONNECTIVITY_MAX - dt.days, 1)
|
elif dt.days > DAYS_NO_CONNECTIVITY_PROMPT:
|
||||||
set_offroad_alert("Offroad_ConnectivityNeededPrompt", True, extra_text=f"{remaining} day{'' if remaining == 1 else 's'}.")
|
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:
|
def check_for_update(self) -> None:
|
||||||
cloudlog.info("checking for updates")
|
cloudlog.info("checking for updates")
|
||||||
|
@ -417,7 +419,7 @@ def main() -> None:
|
||||||
params.put("InstallDate", t.encode('utf8'))
|
params.put("InstallDate", t.encode('utf8'))
|
||||||
|
|
||||||
updater = Updater()
|
updater = Updater()
|
||||||
update_failed_count = 0 # TODO: Load from param?
|
update_failed_count = 0 # TODO: Load from param?
|
||||||
|
|
||||||
# no fetch on the first time
|
# no fetch on the first time
|
||||||
wait_helper = WaitTimeHelper()
|
wait_helper = WaitTimeHelper()
|
||||||
|
@ -437,7 +439,12 @@ def main() -> None:
|
||||||
init_overlay()
|
init_overlay()
|
||||||
|
|
||||||
# ensure we have some params written soon after startup
|
# 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
|
update_failed_count += 1
|
||||||
|
|
||||||
# check for update
|
# check for update
|
||||||
|
@ -466,7 +473,8 @@ def main() -> None:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
params.put("UpdaterState", "idle")
|
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:
|
except Exception:
|
||||||
cloudlog.exception("uncaught updated exception while setting params, shouldn't happen")
|
cloudlog.exception("uncaught updated exception while setting params, shouldn't happen")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue