7 Commits

Author SHA1 Message Date
serversdown 3dadac4bcb Merge pull request 'feat: add optional mirror server config' (#5) from feat/mirror-dual-send into dev
Reviewed-on: #5
2026-06-25 01:42:29 -04:00
serversdown 7d22442bad feat: best-effort mirror (dual-send) of heartbeats + events
Optional second destination so each heartbeat and event is posted to a
mirror server (the office NAS) alongside the primary — dual-write to
de-risk the migration. Default off (blank mirror URLs); existing installs
unchanged.

- event_forwarder: mirror_reachable() fast-fail probe + mirror_forward_pass()
  (reliable event mirror with its OWN state file, total exception isolation,
  never raises into the primary path).
- series4_ingest: mirror_api_url/mirror_sfm_url/mirror_sfm_state_file config;
  best-effort heartbeat mirror; isolated event-mirror pass after the primary.
- settings dialog: new 'Mirror' tab.
- 9 new tests incl. the isolation invariant (down mirror = fast no-op that
  never touches primary state). 42 passing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 23:10:50 +00:00
serversdown dae67afeb9 docs: mirror dual-send design spec
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 23:02:47 +00:00
serversdown 997b5f053c chore: bump to version 0.3.1 2026-06-24 22:12:31 +00:00
serversdown 7f2a4a5a96 feat: enhance settings dialog and update check logging 2026-06-24 22:12:31 +00:00
serversdown ac8b58c193 feat: SFM event forwarding added. v0.3.0 2026-06-01 21:31:45 +00:00
claude 4742ed92ba fix: improve MLG file timestamp handling in scan_thordata function. Uses file metadata, not unit reported time. 2026-04-02 17:45:57 -04:00
10 changed files with 425 additions and 20 deletions
+7
View File
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.3.1] - 2026-05-20
### Hot fix
- Improved update logging
- Improved update settings
## [0.3.0] - 2026-05-19
### Added
+3 -3
View File
@@ -1,6 +1,6 @@
# Thor Watcher
**Version:** 0.3.0
**Version:** 0.3.1
Micromate (Series 4) watcher agent for Terra-View fleet management. Runs as a Windows system tray application, scans THORDATA for Micromate unit activity, sends heartbeat data to Terra-View, and (optionally) forwards `.IDFH`/`.IDFW` event files to a seismo-relay SFM server.
@@ -29,7 +29,7 @@ build.bat
```
Produces:
- `dist\thor-watcher-0.3.0.exe` — upload to Gitea release
- `dist\thor-watcher-0.3.1.exe` — upload to Gitea release
- `dist\thor-watcher.exe` — use with Inno Setup
Then run Inno Setup Compiler on `installer.iss` to produce `thor-watcher-setup.exe`.
@@ -121,7 +121,7 @@ Posted to `api_url` on each API interval:
{
"source_id": "THOR-PC",
"source_type": "series4_watcher",
"version": "0.3.0",
"version": "0.3.1",
"generated_at": "2026-03-20T14:30:00Z",
"log_tail": ["...last 25 log lines..."],
"units": [
+5 -1
View File
@@ -24,5 +24,9 @@
"sfm_http_timeout": 60,
"sfm_state_file": "",
"sfm_max_forwards_per_pass": 500,
"sfm_max_event_age_days": 365
"sfm_max_event_age_days": 365,
"mirror_api_url": "",
"mirror_sfm_url": "",
"mirror_sfm_state_file": ""
}
+51
View File
@@ -0,0 +1,51 @@
# Watcher Mirror (Dual-Send) — Design
**Date:** 2026-06-24 · **Branch:** `feat/mirror-dual-send` (both `thor-watcher` + `series3-watcher`) · **Status:** approved, implementing
## Goal
Let each watcher post every heartbeat and event to a **second ("mirror") server** in addition to the primary, so the office NAS stays a continuous replica of prod during the migration. The eventual cutover becomes a non-event. **Default off** → existing installs unchanged.
## Pattern
Classic dual-write migration. The primary path stays **exactly as reliable as today**; the mirror is pure best-effort bonus that can **never delay or fail** the primary.
## The two watchers (parallel changes)
| | thor-watcher (series4) | series3-watcher (s3) |
|---|---|---|
| Config | `config.json` (JSON) | `config.ini` (`[agent]`, INI) |
| Heartbeat fn | `send_api_payload(payload, api_url, timeout)` | `send_api_payload(payload, api_url)` |
| Event fn | `event_forwarder.forward_pending(root, sfm_url, state, …)` | same (`event_forwarder` is a sibling port) |
| Loop | `series4_ingest.run_watcher` | `series3_watcher.run_watcher` |
| Settings GUI | `thor_settings_dialog.py` | `settings_dialog.py` |
## Design (Approach A — reliable event mirror, best-effort heartbeat)
### Config additions (default empty = off)
- thor (`config.json`): `mirror_api_url`, `mirror_sfm_url`, `mirror_sfm_state_file` (blank → `<log_dir>/thor_forwarded_mirror.json`).
- s3 (`config.ini`): `MIRROR_API_URL`, `MIRROR_SFM_URL`, `MIRROR_SFM_STATE_FILE` (blank → `sfm_forwarded_mirror.json`).
The mirror **rides along** with the primary: heartbeat-mirror active iff primary heartbeat on **and** `mirror_api_url` set; event-mirror active iff primary forwarding on **and** `mirror_sfm_url` set. No separate enable flag.
### Heartbeat mirror (best-effort)
After the primary `send_api_payload`, if `mirror_api_url` is set, fire one more `send_api_payload(payload, mirror_api_url, …)`. Wrapped so it can never raise into the loop; result ignored except a debug log. Bounded by the existing short API timeout (~5 s).
### Event mirror (reliable, isolated)
- Init a **second** `ForwardState(mirror_state_path)` alongside the primary state.
- Each forward tick, **after** the primary `forward_pending`, run a second `forward_pending(root, mirror_sfm_url, mirror_state, …)` in its **own** try/except.
- **Reachability guard:** before the mirror forward, a quick TCP/HTTP probe of `mirror_sfm_url` (~3 s). If unreachable → skip this pass, log, retry next tick. Prevents a down NAS from stalling the loop on per-event timeouts. The mirror state file means skipped events stay pending → delivered when the NAS returns. **No data loss.**
- Reliable + idempotent via its own sha256 state, fully independent of the primary's state.
### Isolation invariant (the one rule)
Nothing on the mirror path can delay or fail the primary: separate state file, its own try/except, the reachability guard + bounded timeouts, all exceptions swallowed-and-logged.
### Settings dialog
Add `Mirror API URL` + `Mirror SFM URL` fields (blank = off) to each watcher's settings dialog.
## Seeding (operational, for this migration)
The mirror state file should reflect what the NAS already has (everything ≤ the migration snapshot, ~16:23 on 2026-06-24). Recipe: copy the primary state file → mirror state file, then drop entries whose `forwarded_at` is after the snapshot, so the mirror re-delivers exactly the gap. SFM-side dedup covers any overlap. (If a watcher had no events in the gap, a straight copy suffices.)
## Testing
- thor `test_event_forwarder.py`: mirror uses a separate state file (idempotent, independent); a mirror failure leaves the primary's result + state untouched; reachability guard skips cleanly when the mirror is down.
- s3: add a minimal test for the same isolation/idempotency.
## Out of scope / handoff
Rebuilding the Windows installers + redeploying (s3 on the Win7 box, thor on the Win10 box) is the operator's job — this change is **code + tests only**.
+68
View File
@@ -692,6 +692,74 @@ def forward_pending(
return counts
# ── Mirror (dual-send) ────────────────────────────────────────────────────────
def mirror_reachable(base_url: str, timeout: float = 3.0) -> bool:
"""Quick liveness probe of a mirror SFM base URL.
Run before a mirror forward pass so an unreachable mirror can't stall
the watcher loop on a per-event HTTP timeout for every pending file.
Probes ``<base>/health`` (the SFM server exposes it). ANY HTTP
response — even 404/500 — means the server is up, so proceed; only a
connection-level failure (refused / timed out / DNS) counts as down.
Best-effort: never raises.
"""
if not base_url:
return False
url = base_url.rstrip("/") + "/health"
try:
with urllib.request.urlopen(
urllib.request.Request(url, method="GET"), timeout=timeout
):
return True
except urllib.error.HTTPError:
return True # got a status back → server is alive
except Exception:
return False # refused / timeout / DNS / socket → down
def mirror_forward_pass(
watch_dir: str,
mirror_url: str,
mirror_state: ForwardState,
*,
reachable_fn=mirror_reachable,
reachable_timeout: float = 3.0,
**forward_kwargs: Any,
) -> Optional[Dict[str, int]]:
"""One best-effort forwarding pass against a *mirror* SFM server.
The dual-send entry point. Wraps :func:`forward_pending` with two
properties that keep the mirror from ever harming the primary path:
1. **Fast-fail reachability guard** — probe ``mirror_url`` first; if
it's down, return ``None`` immediately rather than let
:func:`forward_pending` block on a per-event timeout for every
pending file.
2. **Total exception isolation** — any error (probe, forward, state
I/O) is swallowed and reported as ``None``. This function NEVER
raises, so the caller's already-completed primary forward is
untouched.
The mirror keeps its OWN ``ForwardState`` file, so its idempotency
and retry are independent of the primary's. Nothing is lost while
the mirror is down — skipped events stay pending and are delivered
on a later pass once it returns.
Returns the :func:`forward_pending` counts dict on a completed pass,
or ``None`` if the mirror was unreachable or the pass raised.
"""
try:
if not mirror_url:
return None
if not reachable_fn(mirror_url, reachable_timeout):
return None
return forward_pending(watch_dir, mirror_url, mirror_state, **forward_kwargs)
except Exception:
return None
# ── Seed-state mode (skip historical backfill on first deploy) ────────────────
+1 -1
View File
@@ -3,7 +3,7 @@
[Setup]
AppName=Thor Watcher
AppVersion=0.2.0
AppVersion=0.3.1
AppPublisher=Terra-Mechanics Inc.
DefaultDirName={pf}\ThorWatcher
DefaultGroupName=Thor Watcher
+70 -3
View File
@@ -1,5 +1,5 @@
"""
Thor Watcher — Series 4 Ingest Agent v0.3.0
Thor Watcher — Series 4 Ingest Agent v0.3.1
Micromate (Series 4) ingest agent for Terra-View.
@@ -29,7 +29,7 @@ import event_forwarder
# ── Version ───────────────────────────────────────────────────────────────────
VERSION = "0.3.0"
VERSION = "0.3.1"
# ── Config ────────────────────────────────────────────────────────────────────
@@ -69,6 +69,15 @@ def load_config(config_path: str) -> Dict[str, Any]:
"sfm_state_file": "", # blank → <log_dir>/thor_forwarded.json
"sfm_max_forwards_per_pass": 500,
"sfm_max_event_age_days": 365,
# Mirror (dual-send) — best-effort second destination, default OFF.
# See docs/mirror-dual-send-design.md. Heartbeat-mirror fires iff
# api_url AND mirror_api_url are set; event-mirror runs iff SFM
# forwarding is on AND mirror_sfm_url is set. Own state file →
# idempotency independent of the primary.
"mirror_api_url": "",
"mirror_sfm_url": "",
"mirror_sfm_state_file": "", # blank → <log_dir>/thor_forwarded_mirror.json
}
with open(config_path, "r", encoding="utf-8") as f:
@@ -168,8 +177,16 @@ def scan_thordata(root: str) -> Dict[str, Dict[str, Any]]:
parsed = parse_mlg_filename(fname)
if not parsed:
continue
unit_id, ts = parsed
unit_id, _ = parsed # keep unit_id only
full_path = os.path.join(unit_path, fname)
try:
mtime = os.path.getmtime(full_path)
ts = datetime.fromtimestamp(mtime)
except Exception:
continue
current = unit_map.get(unit_id)
if current is None or ts > current["last_call"]:
unit_map[unit_id] = {
@@ -321,6 +338,12 @@ def run_watcher(state: Dict[str, Any], stop_event: threading.Event) -> None:
sfm_state_path = str(cfg.get("sfm_state_file", "")).strip() or \
os.path.join(state["log_dir"], "thor_forwarded.json")
# Mirror (dual-send) config
MIRROR_API_URL = str(cfg.get("mirror_api_url", "")).strip()
MIRROR_SFM_URL = str(cfg.get("mirror_sfm_url", "")).strip()
mirror_state_path = str(cfg.get("mirror_sfm_state_file", "")).strip() or \
os.path.join(state["log_dir"], "thor_forwarded_mirror.json")
log_message(log_file, ENABLE_LOGGING,
"[cfg] THORDATA_PATH={} SCAN_INTERVAL={}s API_INTERVAL={}s API={} SFM={}".format(
THORDATA_PATH, SCAN_INTERVAL, API_INTERVAL, bool(API_URL),
@@ -354,6 +377,24 @@ def run_watcher(state: Dict[str, Any], stop_event: threading.Event) -> None:
else:
state["sfm_status"] = "disabled"
# Mirror event-forward state — independent of the primary's. Created
# only when the primary forwarder is on AND a mirror URL is set.
mirror_state_obj: Optional[event_forwarder.ForwardState] = None
if sfm_state_obj is not None and MIRROR_SFM_URL:
try:
mirror_state_obj = event_forwarder.ForwardState(mirror_state_path)
log_message(log_file, ENABLE_LOGGING,
"[mirror] event mirror ready url={} state={} known={}".format(
MIRROR_SFM_URL, mirror_state_path, mirror_state_obj.count()))
print("[MIRROR] event mirror ready url={}".format(MIRROR_SFM_URL))
except Exception as exc:
log_message(log_file, ENABLE_LOGGING,
"[mirror] event mirror init failed: {}".format(exc))
mirror_state_obj = None
if MIRROR_API_URL:
log_message(log_file, ENABLE_LOGGING,
"[mirror] heartbeat mirror enabled url={}".format(MIRROR_API_URL))
state["last_forward"] = None
state["last_forward_counts"] = None
@@ -411,6 +452,13 @@ def run_watcher(state: Dict[str, Any], stop_event: threading.Event) -> None:
payload["log_tail"] = _read_log_tail(log_file, 25)
response = send_api_payload(payload, API_URL, API_TIMEOUT)
last_api_ts = now_ts
# Best-effort heartbeat mirror — never affects primary.
if MIRROR_API_URL:
try:
send_api_payload(payload, MIRROR_API_URL, API_TIMEOUT)
except Exception as exc:
log_message(log_file, ENABLE_LOGGING,
"[mirror] heartbeat post failed: {}".format(exc))
if response is not None:
state["api_status"] = "ok"
if response.get("update_available"):
@@ -451,6 +499,25 @@ def run_watcher(state: Dict[str, Any], stop_event: threading.Event) -> None:
print(msg)
log_message(log_file, ENABLE_LOGGING, msg)
# Best-effort event mirror — own state, fast-fail guard,
# fully isolated. Runs after the primary each tick.
if mirror_state_obj is not None:
m_counts = event_forwarder.mirror_forward_pass(
THORDATA_PATH, MIRROR_SFM_URL, mirror_state_obj,
max_age_days=SFM_MAX_AGE_DAYS,
quiescence_seconds=SFM_QUIESCENCE,
missing_report_grace_seconds=SFM_GRACE,
timeout=SFM_HTTP_TIMEOUT,
max_per_pass=SFM_MAX_PER_PASS,
logger=lambda m: log_message(log_file, ENABLE_LOGGING, "[mirror] " + m),
)
if m_counts is None:
log_message(log_file, ENABLE_LOGGING,
"[mirror] forward skipped (unreachable/error): {}".format(MIRROR_SFM_URL))
else:
log_message(log_file, ENABLE_LOGGING,
"[mirror] pass forwarded={forwarded} errors={errors}".format(**m_counts))
except Exception as e:
err = "[loop-error] {}".format(e)
print(err)
+129
View File
@@ -712,5 +712,134 @@ class TestForwardPending(unittest.TestCase):
self.assertEqual(len(_FakeImportHandler.received), 2)
# ── Mirror (dual-send) ───────────────────────────────────────────────────────
class TestMirrorReachable(unittest.TestCase):
def test_empty_url_is_unreachable(self):
self.assertFalse(ef.mirror_reachable("", timeout=1.0))
def test_dead_port_is_unreachable_and_fast(self):
# Nothing listens on 127.0.0.1:1 → connection refused → False,
# and it must NOT hang (this is the whole point of the guard).
t0 = time.time()
self.assertFalse(ef.mirror_reachable("http://127.0.0.1:1", timeout=2.0))
self.assertLess(time.time() - t0, 2.5)
def test_any_http_response_counts_as_reachable(self):
# The fake server 501s on GET /health, but it's UP — so reachable.
server, base = _start_fake_server()
try:
self.assertTrue(ef.mirror_reachable(base, timeout=2.0))
finally:
server.shutdown()
server.server_close()
class TestMirrorForwardPass(unittest.TestCase):
"""The dual-send entry point: best-effort, isolated, own state."""
def setUp(self):
_FakeImportHandler.received = []
self.server, self.base_url = _start_fake_server()
def tearDown(self):
self.server.shutdown()
self.server.server_close()
def _one_event(self, root: Path) -> None:
unit = _make_thordata(root, "Project A", "UM11719")
_make_event(unit, "UM11719_20231219163444.IDFW", age_seconds=200, content=b"binary")
_make_txt(unit, "UM11719_20231219163444.IDFW", age_seconds=100, content=b"report")
def test_empty_mirror_url_is_noop(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
self._one_event(root)
mstate = ef.ForwardState(str(root / "mirror.json"))
self.assertIsNone(ef.mirror_forward_pass(str(root), "", mstate, max_age_days=30))
self.assertEqual(len(_FakeImportHandler.received), 0)
def test_skips_when_unreachable_without_posting(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
self._one_event(root)
mstate = ef.ForwardState(str(root / "mirror.json"))
result = ef.mirror_forward_pass(
str(root), self.base_url, mstate,
reachable_fn=lambda url, timeout=3.0: False, # force "down"
max_age_days=30, quiescence_seconds=5,
missing_report_grace_seconds=60, timeout=5.0,
)
self.assertIsNone(result)
self.assertEqual(mstate.count(), 0) # nothing forwarded
self.assertEqual(len(_FakeImportHandler.received), 0) # never POSTed
def test_forwards_when_reachable_using_its_own_state(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
self._one_event(root)
mstate = ef.ForwardState(str(root / "mirror.json"))
counts = ef.mirror_forward_pass(
str(root), self.base_url, mstate,
reachable_fn=lambda url, timeout=3.0: True,
max_age_days=30, quiescence_seconds=5,
missing_report_grace_seconds=60, timeout=5.0,
)
self.assertIsNotNone(counts)
self.assertEqual(counts["forwarded"], 1)
self.assertEqual(mstate.count(), 1)
self.assertEqual(len(_FakeImportHandler.received), 1)
def test_never_raises_when_forward_blows_up(self):
# Even if forward_pending raises, the mirror swallows it → None.
def _boom(*a, **k):
raise RuntimeError("boom")
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
self._one_event(root)
mstate = ef.ForwardState(str(root / "mirror.json"))
orig = ef.forward_pending
ef.forward_pending = _boom
try:
result = ef.mirror_forward_pass(
str(root), self.base_url, mstate,
reachable_fn=lambda url, timeout=3.0: True,
max_age_days=30,
)
finally:
ef.forward_pending = orig
self.assertIsNone(result)
def test_down_mirror_leaves_primary_state_untouched(self):
# The invariant: a real down mirror (via the real reachability
# probe) is a fast no-op and the primary forward is unaffected.
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
self._one_event(root)
primary_state = ef.ForwardState(str(root / "primary.json"))
pcounts = ef.forward_pending(
str(root), self.base_url, primary_state,
max_age_days=30, quiescence_seconds=5,
missing_report_grace_seconds=60, timeout=5.0,
)
self.assertEqual(pcounts["forwarded"], 1)
primary_snapshot = primary_state.count()
mstate = ef.ForwardState(str(root / "mirror.json"))
t0 = time.time()
result = ef.mirror_forward_pass(
str(root), "http://127.0.0.1:1", mstate, # nothing listens
max_age_days=30, quiescence_seconds=5,
missing_report_grace_seconds=60, timeout=5.0,
)
self.assertIsNone(result)
self.assertLess(time.time() - t0, 3.5) # fast-failed, didn't hang
self.assertEqual(mstate.count(), 0)
self.assertEqual(primary_state.count(), primary_snapshot) # untouched
if __name__ == "__main__":
unittest.main()
+82 -6
View File
@@ -1,5 +1,5 @@
"""
Thor Watcher — Settings Dialog v0.3.0
Thor Watcher — Settings Dialog v0.3.1
Provides a Tkinter settings dialog that doubles as a first-run wizard.
@@ -47,6 +47,11 @@ DEFAULTS = {
"sfm_state_file": "",
"sfm_max_forwards_per_pass": 500,
"sfm_max_event_age_days": 365,
# Mirror (dual-send) — best-effort second destination, default OFF.
"mirror_api_url": "",
"mirror_sfm_url": "",
"mirror_sfm_state_file": "",
}
@@ -220,6 +225,14 @@ class SettingsDialog:
self.var_sfm_max_age_days = tk.StringVar(value=str(v.get("sfm_max_event_age_days", 365)))
self.var_sfm_state_file = tk.StringVar(value=str(v.get("sfm_state_file", "")))
# Mirror (dual-send) — best-effort second destination
raw_mirror = str(v.get("mirror_api_url", ""))
if raw_mirror.endswith(_suffix):
raw_mirror = raw_mirror[:-len(_suffix)]
self.var_mirror_api_url = tk.StringVar(value=raw_mirror)
self.var_mirror_sfm_url = tk.StringVar(value=str(v.get("mirror_sfm_url", "")))
self.var_mirror_sfm_state_file = tk.StringVar(value=str(v.get("mirror_sfm_state_file", "")))
# ── UI construction ───────────────────────────────────────────────────────
def _build_ui(self):
@@ -245,6 +258,7 @@ class SettingsDialog:
self._build_tab_scanning(nb)
self._build_tab_logging(nb)
self._build_tab_forwarding(nb)
self._build_tab_mirror(nb)
self._build_tab_updates(nb)
btn_frame = tk.Frame(outer)
@@ -484,15 +498,67 @@ class SettingsDialog:
finally:
self._sfm_test_btn.config(state="normal")
def _build_tab_mirror(self, nb):
f = self._tab_frame(nb, "Mirror")
intro = (
"Optional dual-send: post each heartbeat and event to a SECOND\n"
"(\"mirror\") server in addition to the primary. Best-effort — the\n"
"mirror can never delay or fail the primary. Leave blank to disable."
)
tk.Label(f, text=intro, justify="left", fg="#1a5276", wraplength=420).grid(
row=0, column=0, columnspan=2, sticky="w", padx=(8, 8), pady=(6, 8)
)
_add_label_entry(f, 1, "Mirror Terra-View URL", self.var_mirror_api_url)
_add_label_entry(f, 2, "Mirror SFM URL", self.var_mirror_sfm_url)
def browse_mirror_state():
p = filedialog.asksaveasfilename(
title="Select Mirror State File",
defaultextension=".json",
filetypes=[("JSON files", "*.json"), ("All files", "*.*")],
initialfile=os.path.basename(
self.var_mirror_sfm_state_file.get() or "thor_forwarded_mirror.json"),
initialdir=os.path.dirname(self.var_mirror_sfm_state_file.get() or "C:\\"),
)
if p:
self.var_mirror_sfm_state_file.set(p.replace("/", "\\"))
_add_label_browse_entry(f, 3, "Mirror State File", self.var_mirror_sfm_state_file,
browse_mirror_state)
help_text = (
"Mirror Terra-View URL → base like http://10.0.0.x:8001 (heartbeats).\n"
"Mirror SFM URL → base like http://10.0.0.x:8200 (events).\n"
"The event mirror keeps its OWN state file, so nothing is lost while\n"
"the mirror is down — pending events are delivered once it returns.\n"
"A quick reachability check skips the mirror cleanly when unreachable,\n"
"so the primary is never slowed.\n"
"State file blank → defaults to <log_dir>\\thor_forwarded_mirror.json."
)
tk.Label(f, text=help_text, justify="left", fg="#555555", wraplength=420).grid(
row=4, column=0, columnspan=2, sticky="w", padx=(8, 8), pady=(8, 4)
)
def _build_tab_updates(self, nb):
f = self._tab_frame(nb, "Updates")
tk.Label(f, text="Auto-Update Source", anchor="w").grid(
# Current version display
tk.Label(f, text="Current Version", anchor="w").grid(
row=0, column=0, sticky="w", padx=(8, 4), pady=(8, 2)
)
tk.Label(
f, text="v{}".format(watcher.VERSION), anchor="w",
font=("TkDefaultFont", 9, "bold"),
).grid(row=0, column=1, sticky="w", padx=(0, 8), pady=(8, 2))
tk.Label(f, text="Auto-Update Source", anchor="w").grid(
row=1, column=0, sticky="w", padx=(8, 4), pady=(8, 2)
)
radio_frame = tk.Frame(f)
radio_frame.grid(row=0, column=1, sticky="w", padx=(0, 8), pady=(8, 2))
radio_frame.grid(row=1, column=1, sticky="w", padx=(0, 8), pady=(8, 2))
ttk.Radiobutton(
radio_frame, text="Gitea (default)",
@@ -513,10 +579,10 @@ class SettingsDialog:
).grid(row=0, column=2, sticky="w")
tk.Label(f, text="Update Server URL", anchor="w").grid(
row=1, column=0, sticky="w", padx=(8, 4), pady=4
row=2, column=0, sticky="w", padx=(8, 4), pady=4
)
self._update_url_entry = ttk.Entry(f, textvariable=self.var_update_url, width=42)
self._update_url_entry.grid(row=1, column=1, sticky="ew", padx=(0, 8), pady=4)
self._update_url_entry.grid(row=2, column=1, sticky="ew", padx=(0, 8), pady=4)
tk.Label(
f,
@@ -528,7 +594,7 @@ class SettingsDialog:
"still works when disabled."
),
justify="left", fg="#555555", wraplength=380,
).grid(row=2, column=0, columnspan=2, sticky="w", padx=(8, 8), pady=(4, 8))
).grid(row=3, column=0, columnspan=2, sticky="w", padx=(8, 8), pady=(4, 8))
self._on_update_source_change()
@@ -590,6 +656,12 @@ class SettingsDialog:
sfm_url = ""
sfm_url = sfm_url.rstrip("/") # event_forwarder adds the endpoint path
# Mirror (dual-send) — best-effort second destination.
mirror_api_url = self.var_mirror_api_url.get().strip()
if mirror_api_url:
mirror_api_url = mirror_api_url.rstrip("/") + "/api/series4/heartbeat"
mirror_sfm_url = self.var_mirror_sfm_url.get().strip().rstrip("/")
values = {
"thordata_path": self.var_thordata_path.get().strip(),
"scan_interval": int_values["Scan Interval"],
@@ -614,6 +686,10 @@ class SettingsDialog:
"sfm_max_forwards_per_pass": int_values["Max Forwards Per Pass"],
"sfm_max_event_age_days": int_values["Max Event Age (days)"],
"sfm_state_file": self.var_sfm_state_file.get().strip(),
"mirror_api_url": mirror_api_url,
"mirror_sfm_url": mirror_sfm_url,
"mirror_sfm_state_file": self.var_mirror_sfm_state_file.get().strip(),
}
try:
+9 -6
View File
@@ -1,5 +1,5 @@
"""
Thor Watcher — System Tray Launcher v0.3.0
Thor Watcher — System Tray Launcher v0.3.1
Requires: pystray, Pillow, tkinter (stdlib)
Run with: pythonw thor_tray.py (no console window)
@@ -126,17 +126,17 @@ def check_for_update():
cfg = _read_config()
update_source = str(cfg.get("update_source", "gitea")).strip().lower()
update_url = str(cfg.get("update_url", "")).strip()
except Exception:
except Exception as exc:
_update_log("config read failed in check_for_update: {} — defaulting to gitea".format(exc))
update_source = "gitea"
update_url = ""
if update_source == "disabled":
return None, None
_update_log("Checking for update (source={}, version={})".format(
update_source, _CURRENT_VERSION
))
if update_source == "disabled":
return None, None
if update_source == "url":
return _check_for_update_url(update_url)
else:
@@ -472,8 +472,11 @@ class WatcherTray:
def _icon_updater(self):
"""Periodically refresh the tray icon and check for updates."""
_update_log("Updater thread started (version={}, first check in ~30s)".format(_CURRENT_VERSION))
last_status = None
update_check_counter = 0 # check every ~5 min (30 × 10s ticks)
# Initial first-check fires at counter==3 (~30s) so we get a confirmation
# line in the log soon after startup; subsequent checks every ~5 min.
update_check_counter = 27
while not self.stop_event.is_set():
icon_status = self._tray_status()