From f0aff3caa5b7ad955ad45fbe779108e665322930 Mon Sep 17 00:00:00 2001 From: brockdarnold Date: Sun, 14 Jun 2026 15:15:21 +0000 Subject: [PATCH] publish eve_autoupdate.py --- eve_autoupdate.py | 82 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 eve_autoupdate.py diff --git a/eve_autoupdate.py b/eve_autoupdate.py new file mode 100644 index 0000000..94fcd95 --- /dev/null +++ b/eve_autoupdate.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +"""Auto-update poller — this is what makes 'push' updates work. + +Runs headless alongside the other watchers (launched by start-all.ps1). Every few +minutes it asks the public repo for the latest commit; when it changes (i.e. new +watcher code was published from Rocky), it pulls the update and restarts the +watchers automatically — within ~3 minutes, no logon/daily wait. Publishing new +code IS the push. + +It updates the data watchers but not itself; its own code refreshes on the next +logon/daily update.py run (which restarts everything cleanly). +""" +import glob +import json +import os +import sys +import time +import urllib.request + +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, HERE) +import update as u # update_code(), restart_mining_watchers() + +BRANCH_API = ("https://git.armoredarmadillo.com/api/v1/repos/" + "brockdarnold/eve-watcher/branches/main") +MARKER = os.path.join(HERE, ".update_sha") +POLL = 180 # seconds between checks (~3 min) + + +def latest_sha(): + req = urllib.request.Request(BRANCH_API, headers={"User-Agent": "eve-watcher-updater"}) + return json.load(urllib.request.urlopen(req, timeout=20))["commit"]["id"] + + +def read_marker(): + try: + return open(MARKER).read().strip() + except Exception: + return "" + + +def write_marker(s): + try: + with open(MARKER, "w") as f: + f.write(s) + except Exception: + pass + + +def main(): + print("[autoupdate] poller started") + if not read_marker(): # seed so we don't update on the very first tick + try: + write_marker(latest_sha()) + except Exception: + pass + while True: + time.sleep(POLL) + try: + sha = latest_sha() + except Exception as e: + print(f"[autoupdate] sha check failed: {e}") + continue + if not sha or sha == read_marker(): + continue + print(f"[autoupdate] new version {sha[:7]} published — updating...") + try: + u.update_code() # git or zip + for hb in glob.glob(os.path.join(HERE, ".hb_*")): # re-announce after update + try: + os.remove(hb) + except Exception: + pass + u.restart_mining_watchers() # onto the new code + write_marker(sha) + print("[autoupdate] updated + restarted watchers.") + except Exception as e: + print(f"[autoupdate] update failed: {e}") + + +if __name__ == "__main__": + main()