publish eve_autoupdate.py
This commit is contained in:
parent
bfd8984f38
commit
f0aff3caa5
1 changed files with 82 additions and 0 deletions
82
eve_autoupdate.py
Normal file
82
eve_autoupdate.py
Normal file
|
|
@ -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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue