Reconcile proven completed inputs without replay and hide internal fact notices
This commit is contained in:
@@ -7,10 +7,28 @@ from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from worker import atomic_json,session_lock
|
||||
from worker import atomic_json,session_lock,reconcile_completed
|
||||
from control import Client
|
||||
from faults import report_process
|
||||
|
||||
|
||||
def recover_worker(cfg,process=None):
|
||||
"""Reconcile a stopped worker under its own lock; never execute its input."""
|
||||
if process is not None and process.poll() is None:return False
|
||||
identity=json.dumps({'control':cfg['control'],'session_id':cfg['session_id']},sort_keys=True)
|
||||
try:
|
||||
with session_lock(identity):
|
||||
path=Path(cfg['state_file']).expanduser()
|
||||
if not path.exists():return False
|
||||
state=json.loads(path.read_text(encoding='utf-8'))
|
||||
if not (state.get('inflight') and state.get('needs_reconciliation')):return False
|
||||
if not cfg.get('thread_id'):return False
|
||||
return reconcile_completed(path,Client(cfg['control']),cfg['session_id'],cfg['thread_id'])
|
||||
except Exception:
|
||||
# Offline, writer still locked, or evidence incomplete: preserve uncertainty.
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
parser=argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--config',required=True)
|
||||
@@ -36,6 +54,8 @@ def main():
|
||||
while True:
|
||||
state_path=Path(cfg['state_file']).expanduser()
|
||||
state=json.loads(state_path.read_text(encoding='utf-8')) if state_path.exists() else {}
|
||||
if recover_worker(cfg,processes.get('worker')):
|
||||
state=json.loads(state_path.read_text(encoding='utf-8'))
|
||||
for role in roles:
|
||||
process=processes.get(role)
|
||||
if process and cfg.get('notification_targets'):
|
||||
@@ -59,9 +79,10 @@ def main():
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
for process in processes.values():
|
||||
if process.poll() is None:process.terminate()
|
||||
for process in processes.values():
|
||||
for role,process in processes.items():
|
||||
if role!='worker' and process.poll() is None:process.terminate()
|
||||
for role,process in processes.items():
|
||||
if role=='worker' and process.poll() is None:continue
|
||||
try:process.wait(timeout=10)
|
||||
except subprocess.TimeoutExpired:process.kill()
|
||||
for stream in logs.values():stream.close()
|
||||
|
||||
Reference in New Issue
Block a user