"""Recoverable DB outbox -> persistent Valkey Streams (at least once).""" import argparse import json import signal import threading from psycopg.rows import dict_row from app import store from pipeline import broker, envelope, STREAM stop=threading.Event() def publish_once(client): with store.connect() as conn: # Marking published happens AFTER XADD. A crash in between produces a # duplicate. DB remains authoritative; no acknowledged intent is lost. rows=conn.cursor(row_factory=dict_row).execute("""SELECT j.* FROM outbox o JOIN jobs j ON j.id=o.job_id WHERE j.state IN ('queued','processing') AND j.next_at<=now() AND (o.published_at IS NULL OR (j.state='processing' AND j.lease_until