45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Durable Stage 2 pipeline: adapter → outbox → JetStream → idempotent consumer."""
|
|
import asyncio
|
|
import signal
|
|
import time
|
|
|
|
from adapters import audit360, jellyfin_media, seerr_requests
|
|
from event_store import connect, init
|
|
from nats_relay import consume_once, relay_once
|
|
|
|
STOP = False
|
|
|
|
|
|
def _stop(*_):
|
|
global STOP
|
|
STOP = True
|
|
|
|
|
|
def main():
|
|
signal.signal(signal.SIGTERM, _stop)
|
|
signal.signal(signal.SIGINT, _stop)
|
|
conn = connect()
|
|
init(conn)
|
|
conn.close()
|
|
print("events-pipeline start", flush=True)
|
|
while not STOP:
|
|
try:
|
|
conn = connect()
|
|
init(conn)
|
|
emitted = audit360(conn) + jellyfin_media(conn) + seerr_requests(conn)
|
|
conn.close()
|
|
relayed = asyncio.run(relay_once())
|
|
consumed = asyncio.run(consume_once(timeout=2))
|
|
print("tick emitted=%s relayed=%s consumed=%s" % (emitted, relayed, consumed), flush=True)
|
|
except Exception as e:
|
|
print("tick_error", str(e)[:300], flush=True)
|
|
for _ in range(5):
|
|
if STOP:
|
|
break
|
|
time.sleep(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|