Compare commits
10 Commits
3dadac4bcb
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 56d2027d08 | |||
| a92afd64cd | |||
| 302934ced6 | |||
| 3bef58b8dd | |||
| 05429bdda3 | |||
| 5340332f32 | |||
| 4870f3ee87 | |||
| 76387ad17a | |||
| 4312efc15c | |||
| 0e2fe7c1e3 |
@@ -5,6 +5,38 @@ 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/),
|
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).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [0.4.1] - 2026-06-25
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- **Auto-updater no longer dies when settings are saved.** Saving the Settings dialog restarts the watcher thread via `_restart_watcher`, which sets and then replaces the shared `stop_event`. Because the updater loop keyed off that *same* event, saving settings would terminate the auto-updater thread (a race — it could survive one save and die on the next). The watcher kept running and reporting heartbeats normally, but the agent silently stopped checking for / applying updates until the tray app was relaunched. The updater now keys off its own app-lifetime event (`_app_stop`) that watcher restarts never touch; it stops only on Exit or when applying an update.
|
||||||
|
- Added `test_thor_tray.py` covering the tray thread lifecycle (updater survives a watcher restart; stops on app exit; `_exit`/`_do_update` signal the lifetime event).
|
||||||
|
|
||||||
|
## [0.4.0] - 2026-06-25
|
||||||
|
|
||||||
|
### Added — Mirror (dual-send)
|
||||||
|
- **Optional best-effort mirror server.** Each heartbeat and each forwarded event can now be sent to a *second* ("mirror") server in addition to the primary, so a standby box (e.g. the office NAS) stays a continuous replica during a migration — making the eventual cutover a non-event. **Default off** — blank `mirror_api_url`/`mirror_sfm_url` means existing installs are unchanged after auto-update.
|
||||||
|
- **Heartbeat mirror (best-effort).** After the primary heartbeat POST, the same payload is fired at `mirror_api_url` when set. Bounded by the existing API timeout and fully wrapped — it can never delay or fail the primary heartbeat; its result is ignored except for a debug log line.
|
||||||
|
- **Event mirror (reliable, isolated).** Events are re-forwarded to `mirror_sfm_url` using a *separate* sha256 state file (`mirror_sfm_state_file`, blank → `<log_dir>/thor_forwarded_mirror.json`), so the mirror tracks its own delivery independently of the primary. A quick reachability probe (~3 s) skips the mirror pass when the mirror server is down, so a dead mirror never stalls the loop on per-event timeouts; skipped events stay pending in the mirror state and deliver when the mirror returns — **no data loss**.
|
||||||
|
- **Isolation invariant (the one rule).** Nothing on the mirror path can delay or fail the primary: its own state file, its own try/except, the reachability guard + bounded timeouts, all exceptions swallowed-and-logged. The primary path stays exactly as reliable as before.
|
||||||
|
- **Mirror tab in the Settings dialog** with `Mirror API URL` + `Mirror SFM URL` fields (blank = off). The mirror rides along with the primary — there is no separate enable flag (heartbeat-mirror active iff the primary heartbeat is on *and* `mirror_api_url` is set; event-mirror active iff primary forwarding is on *and* `mirror_sfm_url` is set).
|
||||||
|
- New unit tests in `test_event_forwarder.py` covering mirror reachability, the down-mirror skip, separate-state idempotency, and the isolation invariant (a mirror failure leaves the primary's result + state untouched).
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
|
||||||
|
New `config.json` keys (all default-empty = off; existing 0.3.x deployments don't change behaviour on auto-update):
|
||||||
|
|
||||||
|
| Key | Default | Notes |
|
||||||
|
|---|---|---|
|
||||||
|
| `mirror_api_url` | `""` | Second heartbeat destination — same URL form as `api_url` (blank = off) |
|
||||||
|
| `mirror_sfm_url` | `""` | Second SFM base URL, e.g. `http://10.0.0.x:8200` (blank = off) |
|
||||||
|
| `mirror_sfm_state_file` | `""` | Override the mirror's forwarded-sha256 state file. Blank → `<log_dir>\thor_forwarded_mirror.json` |
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Bumped `VERSION` to `0.4.0`
|
||||||
|
|
||||||
|
> **Operational note (migration seeding).** To make the mirror re-deliver only the gap since a one-time replica snapshot, copy the primary state file to the mirror state file and drop entries whose `forwarded_at` is after the snapshot. SFM-side dedup covers any overlap. See `docs/mirror-dual-send-design.md`.
|
||||||
|
|
||||||
|
|
||||||
## [0.3.1] - 2026-05-20
|
## [0.3.1] - 2026-05-20
|
||||||
|
|
||||||
### Hot fix
|
### Hot fix
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
# Thor Watcher
|
# Thor Watcher
|
||||||
|
|
||||||
**Version:** 0.3.1
|
**Version:** 0.4.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.
|
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. Heartbeats and events can optionally be **mirrored** to a second server (e.g. a standby/NAS) in addition to the primary.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ build.bat
|
|||||||
```
|
```
|
||||||
|
|
||||||
Produces:
|
Produces:
|
||||||
- `dist\thor-watcher-0.3.1.exe` — upload to Gitea release
|
- `dist\thor-watcher-0.4.1.exe` — upload to Gitea release
|
||||||
- `dist\thor-watcher.exe` — use with Inno Setup
|
- `dist\thor-watcher.exe` — use with Inno Setup
|
||||||
|
|
||||||
Then run Inno Setup Compiler on `installer.iss` to produce `thor-watcher-setup.exe`.
|
Then run Inno Setup Compiler on `installer.iss` to produce `thor-watcher-setup.exe`.
|
||||||
@@ -71,6 +71,9 @@ Managed through the Settings dialog (right-click tray icon → Settings). A `con
|
|||||||
| `sfm_state_file` | string | `""` | Path to the sha256-keyed state file. Blank → `<log_dir>\thor_forwarded.json` |
|
| `sfm_state_file` | string | `""` | Path to the sha256-keyed state file. Blank → `<log_dir>\thor_forwarded.json` |
|
||||||
| `sfm_max_forwards_per_pass` | integer | `500` | Cap per pass to drip-feed large backfills |
|
| `sfm_max_forwards_per_pass` | integer | `500` | Cap per pass to drip-feed large backfills |
|
||||||
| `sfm_max_event_age_days` | integer | `365` | Skip event files older than this many days |
|
| `sfm_max_event_age_days` | integer | `365` | Skip event files older than this many days |
|
||||||
|
| `mirror_api_url` | string | `""` | Second heartbeat destination (same URL form as `api_url`). Blank → heartbeat mirror off |
|
||||||
|
| `mirror_sfm_url` | string | `""` | Second SFM base URL (e.g. `http://10.0.0.x:8200`). Blank → event mirror off |
|
||||||
|
| `mirror_sfm_state_file` | string | `""` | Path to the mirror's sha256 state file. Blank → `<log_dir>\thor_forwarded_mirror.json` |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -86,6 +89,21 @@ When `sfm_forward_enabled` is true and `sfm_url` is set, Thor Watcher walks the
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Mirror (Dual-Send)
|
||||||
|
|
||||||
|
Thor Watcher can post every heartbeat and event to a **second ("mirror") server** in addition to the primary — useful for keeping a standby box (e.g. the office NAS) as a continuous replica during a server migration, so the eventual cutover is a non-event. **Default off.**
|
||||||
|
|
||||||
|
The mirror rides along with the primary — there is no separate enable flag:
|
||||||
|
|
||||||
|
- **Heartbeat mirror** is active when the API heartbeat is enabled **and** `mirror_api_url` is set. After the primary heartbeat POST, the same payload is fired at `mirror_api_url`.
|
||||||
|
- **Event mirror** is active when SFM forwarding is enabled **and** `mirror_sfm_url` is set. Events are re-forwarded to `mirror_sfm_url` using a **separate** sha256 state file (`mirror_sfm_state_file`, blank → `<log_dir>\thor_forwarded_mirror.json`).
|
||||||
|
|
||||||
|
**The mirror can never delay or fail the primary.** The heartbeat mirror is fully wrapped and bounded by the API timeout. The event mirror runs a quick reachability probe (~3 s) first and skips the pass if the mirror server is down — skipped events stay pending in the mirror state and deliver when it returns, so nothing is lost. All mirror exceptions are swallowed-and-logged; the primary path stays exactly as reliable as before.
|
||||||
|
|
||||||
|
- **Seeding for a migration.** To re-deliver only the gap since a one-time replica snapshot, copy the primary state file to the mirror state file and drop entries whose `forwarded_at` is after the snapshot. SFM-side dedup covers any overlap. See [`docs/mirror-dual-send-design.md`](docs/mirror-dual-send-design.md).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Tray Icon Colors
|
## Tray Icon Colors
|
||||||
|
|
||||||
| Color | Meaning |
|
| Color | Meaning |
|
||||||
@@ -121,7 +139,7 @@ Posted to `api_url` on each API interval:
|
|||||||
{
|
{
|
||||||
"source_id": "THOR-PC",
|
"source_id": "THOR-PC",
|
||||||
"source_type": "series4_watcher",
|
"source_type": "series4_watcher",
|
||||||
"version": "0.3.1",
|
"version": "0.4.1",
|
||||||
"generated_at": "2026-03-20T14:30:00Z",
|
"generated_at": "2026-03-20T14:30:00Z",
|
||||||
"log_tail": ["...last 25 log lines..."],
|
"log_tail": ["...last 25 log lines..."],
|
||||||
"units": [
|
"units": [
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
[Setup]
|
[Setup]
|
||||||
AppName=Thor Watcher
|
AppName=Thor Watcher
|
||||||
AppVersion=0.3.1
|
AppVersion=0.4.1
|
||||||
AppPublisher=Terra-Mechanics Inc.
|
AppPublisher=Terra-Mechanics Inc.
|
||||||
DefaultDirName={pf}\ThorWatcher
|
DefaultDirName={pf}\ThorWatcher
|
||||||
DefaultGroupName=Thor Watcher
|
DefaultGroupName=Thor Watcher
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Thor Watcher — Series 4 Ingest Agent v0.3.1
|
Thor Watcher — Series 4 Ingest Agent v0.4.1
|
||||||
|
|
||||||
Micromate (Series 4) ingest agent for Terra-View.
|
Micromate (Series 4) ingest agent for Terra-View.
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ import event_forwarder
|
|||||||
|
|
||||||
# ── Version ───────────────────────────────────────────────────────────────────
|
# ── Version ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
VERSION = "0.3.1"
|
VERSION = "0.4.1"
|
||||||
|
|
||||||
|
|
||||||
# ── Config ────────────────────────────────────────────────────────────────────
|
# ── Config ────────────────────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
"""
|
||||||
|
Tests for thor_tray's thread lifecycle.
|
||||||
|
|
||||||
|
Regression guard for the bug where saving settings — which restarts the
|
||||||
|
watcher thread via ``_restart_watcher`` — also killed the auto-updater
|
||||||
|
thread, because both shared a single ``stop_event``. The updater must key
|
||||||
|
off a separate lifetime event (``_app_stop``) that a watcher restart never
|
||||||
|
disturbs; it should only stop when the app actually exits.
|
||||||
|
"""
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import threading
|
||||||
|
import unittest
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
# Thor's tray pulls in Windows-only GUI deps at import time; stub them so the
|
||||||
|
# module imports on a headless dev/CI box.
|
||||||
|
for _name in ("pystray", "PIL", "PIL.Image", "PIL.ImageDraw"):
|
||||||
|
sys.modules.setdefault(_name, mock.MagicMock())
|
||||||
|
|
||||||
|
import thor_tray # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
|
class TrayThreadLifecycle(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
# Keep _start_watcher cheap: a no-op watcher loop so restarting the
|
||||||
|
# watcher doesn't spin up the real THORDATA scanner / network heartbeat.
|
||||||
|
patcher = mock.patch.object(
|
||||||
|
thor_tray.watcher, "run_watcher", lambda state, stop_event: None
|
||||||
|
)
|
||||||
|
patcher.start()
|
||||||
|
self.addCleanup(patcher.stop)
|
||||||
|
|
||||||
|
def test_app_stop_is_separate_lifetime_event(self):
|
||||||
|
app = thor_tray.WatcherTray()
|
||||||
|
self.assertIsInstance(app._app_stop, threading.Event)
|
||||||
|
self.assertIsNot(app._app_stop, app.stop_event)
|
||||||
|
self.assertFalse(app._app_stop.is_set())
|
||||||
|
|
||||||
|
def test_exit_signals_app_stop(self):
|
||||||
|
app = thor_tray.WatcherTray()
|
||||||
|
icon = mock.MagicMock()
|
||||||
|
app._exit(icon, None)
|
||||||
|
self.assertTrue(app._app_stop.is_set())
|
||||||
|
icon.stop.assert_called_once()
|
||||||
|
|
||||||
|
def test_restart_watcher_leaves_watcher_stop_unset(self):
|
||||||
|
app = thor_tray.WatcherTray()
|
||||||
|
app._restart_watcher()
|
||||||
|
self.assertFalse(app.stop_event.is_set())
|
||||||
|
|
||||||
|
def test_updater_survives_watcher_restart_then_stops_on_exit(self):
|
||||||
|
app = thor_tray.WatcherTray()
|
||||||
|
app._icon = None
|
||||||
|
with mock.patch.object(thor_tray, "check_for_update", return_value=(None, None)), \
|
||||||
|
mock.patch.object(thor_tray, "_update_log"), \
|
||||||
|
mock.patch.object(app, "_tray_status", return_value="ok"):
|
||||||
|
t = threading.Thread(
|
||||||
|
target=app._icon_updater, daemon=True, name="test-updater"
|
||||||
|
)
|
||||||
|
t.start()
|
||||||
|
time.sleep(0.1)
|
||||||
|
self.assertTrue(t.is_alive(), "updater failed to start")
|
||||||
|
|
||||||
|
# A settings save restarts the watcher — it must NOT kill the updater.
|
||||||
|
app._restart_watcher()
|
||||||
|
time.sleep(0.2)
|
||||||
|
self.assertTrue(
|
||||||
|
t.is_alive(), "updater thread died on watcher restart (the bug)"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Real app exit DOES stop the updater.
|
||||||
|
app._app_stop.set()
|
||||||
|
t.join(timeout=2)
|
||||||
|
self.assertFalse(
|
||||||
|
t.is_alive(), "updater thread did not stop on app exit"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Thor Watcher — Settings Dialog v0.3.1
|
Thor Watcher — Settings Dialog v0.4.1
|
||||||
|
|
||||||
Provides a Tkinter settings dialog that doubles as a first-run wizard.
|
Provides a Tkinter settings dialog that doubles as a first-run wizard.
|
||||||
|
|
||||||
|
|||||||
+7
-4
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Thor Watcher — System Tray Launcher v0.3.1
|
Thor Watcher — System Tray Launcher v0.4.1
|
||||||
Requires: pystray, Pillow, tkinter (stdlib)
|
Requires: pystray, Pillow, tkinter (stdlib)
|
||||||
|
|
||||||
Run with: pythonw thor_tray.py (no console window)
|
Run with: pythonw thor_tray.py (no console window)
|
||||||
@@ -334,7 +334,8 @@ def _show_cancel_message():
|
|||||||
class WatcherTray:
|
class WatcherTray:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.state = {}
|
self.state = {}
|
||||||
self.stop_event = threading.Event()
|
self.stop_event = threading.Event() # watcher lifecycle; replaced on restart
|
||||||
|
self._app_stop = threading.Event() # app lifetime; only set on exit/update
|
||||||
self._watcher_thread = None
|
self._watcher_thread = None
|
||||||
self._icon = None
|
self._icon = None
|
||||||
self._menu_lock = threading.Lock()
|
self._menu_lock = threading.Lock()
|
||||||
@@ -390,6 +391,7 @@ class WatcherTray:
|
|||||||
subprocess.Popen(["explorer", HERE])
|
subprocess.Popen(["explorer", HERE])
|
||||||
|
|
||||||
def _exit(self, icon, item):
|
def _exit(self, icon, item):
|
||||||
|
self._app_stop.set()
|
||||||
self.stop_event.set()
|
self.stop_event.set()
|
||||||
icon.stop()
|
icon.stop()
|
||||||
|
|
||||||
@@ -478,7 +480,7 @@ class WatcherTray:
|
|||||||
# line in the log soon after startup; subsequent checks every ~5 min.
|
# line in the log soon after startup; subsequent checks every ~5 min.
|
||||||
update_check_counter = 27
|
update_check_counter = 27
|
||||||
|
|
||||||
while not self.stop_event.is_set():
|
while not self._app_stop.is_set():
|
||||||
icon_status = self._tray_status()
|
icon_status = self._tray_status()
|
||||||
|
|
||||||
if self._icon is not None:
|
if self._icon is not None:
|
||||||
@@ -504,7 +506,7 @@ class WatcherTray:
|
|||||||
self._do_update(url)
|
self._do_update(url)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.stop_event.wait(timeout=10)
|
self._app_stop.wait(timeout=10)
|
||||||
|
|
||||||
def _do_update(self, download_url=None):
|
def _do_update(self, download_url=None):
|
||||||
"""Notify tray then apply update. If url is None, fetch it first."""
|
"""Notify tray then apply update. If url is None, fetch it first."""
|
||||||
@@ -519,6 +521,7 @@ class WatcherTray:
|
|||||||
|
|
||||||
success = apply_update(download_url)
|
success = apply_update(download_url)
|
||||||
if success:
|
if success:
|
||||||
|
self._app_stop.set()
|
||||||
self.stop_event.set()
|
self.stop_event.set()
|
||||||
if self._icon is not None:
|
if self._icon is not None:
|
||||||
self._icon.stop()
|
self._icon.stop()
|
||||||
|
|||||||
Reference in New Issue
Block a user