Phase 0: repo skeleton, image, compose stacks, doctor, migration runner, frontend shell
New repo for the Packet Station rebuild (Python 3.12, FastAPI, PostgreSQL 16, React, VisualKit, MFilesKit, Docker Compose on docker-1). Nothing is migrated from the M: install. - CLAUDE.md with the safety rules, README, CHANGELOG, docs (BRIEF, PLAN, SECURITY rewritten for the server with the requirement ID table, DEPLOY, stubs for FEED, POLICY, SCHEMA, GO-LIVE, PAPER-FALLBACK). - packetstation CLI: app, worker (heartbeat stub), migrate, doctor, version, healthcheck. Settings from the environment with secret files. Stack guard (test never points at VISUAL production). Security headers and CSP. Trusted proxy resolved by name. JSON logs with redaction. - Migration runner and 0001_base: settings, append-only audit_events with hash chain, ps_notify, grants for ps_app. - Multi-stage Dockerfile (ODBC Driver 18, PESCO libraries from the Gitea index only), compose base, proxy overlay for npm_default, CI overlay, postgres initdb roles, env examples, NPM proxy host notes, Gitea Actions. - Frontend: Vite, React, TypeScript, the PESCO dark theme ported with self-hosted fonts, placeholder sign-in and home. - Verified on docker-1: image builds, CI stack comes up healthy, doctor database checks pass, 77 server tests pass against PostgreSQL. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
"""Phase 0 worker stub: a heartbeat line every 30 s and a touched beat file; exits on SIGTERM."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
import signal
|
||||
import threading
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
log = logging.getLogger("packetstation.worker")
|
||||
|
||||
BEAT_SECONDS = 30
|
||||
STALE_SECONDS = 90
|
||||
|
||||
|
||||
def touch(path: Path) -> None:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.touch(exist_ok=True)
|
||||
now = time.time()
|
||||
os.utime(path, (now, now))
|
||||
|
||||
|
||||
def run(beat_file: Path, build: str, stop: threading.Event | None = None, interval: float = BEAT_SECONDS) -> int:
|
||||
stop = stop or threading.Event()
|
||||
|
||||
def _stop(signum: int, _frame: object) -> None:
|
||||
log.info("worker stopping on signal %s", signum)
|
||||
stop.set()
|
||||
|
||||
if threading.current_thread() is threading.main_thread():
|
||||
signal.signal(signal.SIGTERM, _stop)
|
||||
signal.signal(signal.SIGINT, _stop)
|
||||
log.info("worker started", extra={"ps": {"build": build, "beat_file": str(beat_file)}})
|
||||
while not stop.is_set():
|
||||
try:
|
||||
touch(beat_file)
|
||||
except OSError as e:
|
||||
log.error("can't touch beat file %s: %s", beat_file, e.strerror)
|
||||
log.info("heartbeat", extra={"ps": {"build": build}})
|
||||
stop.wait(interval)
|
||||
log.info("worker stopped")
|
||||
return 0
|
||||
|
||||
|
||||
def beat_age(beat_file: Path) -> float | None:
|
||||
try:
|
||||
return time.time() - beat_file.stat().st_mtime
|
||||
except OSError:
|
||||
return None
|
||||
Reference in New Issue
Block a user