Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46761c0142 | ||
|
|
a221d71971 |
No files matched your search
@@ -40,7 +40,7 @@
|
||||
| S2-03 | S2 | Inbox + effects idempotency | done | | architect | repeat_test 100→1 | 0 | |
|
||||
| S2-04 | S2 | NATS JetStream relay | done | | architect | enqueue1 relayed1 processed1; inbox/effects 1 | 1 | |
|
||||
| S2-05 | S2 | Adapters + ownership matrix | in_progress | | architect | ownership matrix 13 types | 1 | |
|
||||
| S2-06 | S2 | pgvector pilot | open | | architect | pending | 0 | |
|
||||
| S2-06 | S2 | pgvector pilot | done | | architect | nearest pilot-a, top2 pilot-a/pilot-c | 1 | |
|
||||
| S2-07 | S2 | Gate G2 proof | done | YES | architect | 100→1; loss recovered | 1 | G2 |
|
||||
| U-01 | U | Approve PR #192 | done | | roman | chat approval 2026-11-26 · Открыть PR #192 и подтвердить архитектуру | 2 | none |
|
||||
| U-02 | U | Seerr vs Jellyseerr decision | dropped | YES | roman | Seerr audit · Выбрать после evidence | 2 | none |
|
||||
@@ -54,9 +54,8 @@
|
||||
- M / done: 7
|
||||
- S0 / done: 10
|
||||
- S1 / done: 10
|
||||
- S2 / done: 5
|
||||
- S2 / done: 6
|
||||
- S2 / in_progress: 1
|
||||
- S2 / open: 1
|
||||
- U / done: 2
|
||||
- U / dropped: 3
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ Gate G2: повтор события 100 раз = один эффект; пот
|
||||
| S2-02 | Outbox schema + enqueue | done |
|
||||
| S2-03 | Inbox + effects idempotency | done |
|
||||
| S2-04 | NATS JetStream relay | done |
|
||||
| S2-05 | Adapters contract + ownership matrix | in_progress |
|
||||
| S2-05 | Adapters: Audit360 done; Jellyfin/Seerr open | in_progress |
|
||||
| S2-06 | pgvector pilot | done (synthetic infrastructure) |
|
||||
| S2-07 | Gate G2 proof | done |
|
||||
|
||||
@@ -73,6 +73,33 @@ Consumer: `buryans-worker`
|
||||
|
||||
Важно: это инфраструктурный пилот, не production semantic search.
|
||||
|
||||
## Durable pipeline
|
||||
|
||||
Сервис:
|
||||
|
||||
```text
|
||||
events-pipeline.service
|
||||
```
|
||||
|
||||
Делает:
|
||||
|
||||
1. Audit 360 adapter → outbox;
|
||||
2. outbox → NATS JetStream;
|
||||
3. NATS → idempotent inbox/effects;
|
||||
4. повторяет каждые 5 секунд.
|
||||
|
||||
Факт:
|
||||
|
||||
```text
|
||||
outbox published = 43
|
||||
pending = 0
|
||||
inbox = 46
|
||||
effects = 45
|
||||
```
|
||||
|
||||
Примечание: `rag` в SQL_ASCII, поэтому кириллица в payload передаётся
|
||||
как `title_utf8_b64`; ASCII-поле `title_ascii` остаётся для совместимости.
|
||||
|
||||
## Следующий инкремент
|
||||
|
||||
NATS JetStream:
|
||||
|
||||
@@ -24,6 +24,16 @@ Consumer: `buryans-worker`
|
||||
- 100 workers same event → `first_effects=1`, `effects=1`.
|
||||
- NATS e2e: 1 outbox → 1 published → 1 inbox → 1 effect.
|
||||
|
||||
## Durable service
|
||||
|
||||
```text
|
||||
events-pipeline.service
|
||||
```
|
||||
|
||||
Adapter Audit 360 → outbox → NATS → inbox/effects, tick 5s.
|
||||
|
||||
SQL_ASCII note: Cyrillic title is carried as `title_utf8_b64`.
|
||||
|
||||
## Next
|
||||
|
||||
- durable consumer/scheduler service;
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
"""Polling adapters for the Stage 2 event fabric."""
|
||||
import base64
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from event_store import enqueue, event
|
||||
|
||||
|
||||
def _ascii_text(value):
|
||||
return value.encode("ascii", "ignore").decode("ascii")
|
||||
|
||||
|
||||
def _utf8_b64(value):
|
||||
return base64.b64encode(value.encode("utf-8")).decode("ascii")
|
||||
|
||||
|
||||
def _iso(dt):
|
||||
if isinstance(dt, str):
|
||||
return dt
|
||||
return dt.astimezone(timezone.utc).isoformat()
|
||||
|
||||
|
||||
def audit360(conn, limit=100):
|
||||
"""Emit one event per changed Audit 360 item."""
|
||||
with conn.cursor() as cur:
|
||||
cur.execute("select cursor from events.adapter_state where adapter='audit360'")
|
||||
row = cur.fetchone()
|
||||
cursor = row[0] if row and row[0] else "1970-01-01T00:00:00+00:00"
|
||||
cur.execute("""
|
||||
select code,status,title,updated_at
|
||||
from audit.sprint_items
|
||||
where updated_at > %s::timestamptz
|
||||
order by updated_at, code
|
||||
limit %s
|
||||
""", (cursor, limit))
|
||||
rows = cur.fetchall()
|
||||
emitted = 0
|
||||
last = cursor
|
||||
for code, status, title, updated in rows:
|
||||
key = "audit:%s:%s" % (code, _iso(updated))
|
||||
etype = ("audit.finding.closed" if status in ("done", "dropped")
|
||||
else "audit.finding.opened" if status in ("open", "waiting_user")
|
||||
else "audit.finding.updated")
|
||||
ev = event(idempotency_key=key, source="audit360", type_=etype,
|
||||
subject=code, data={"code": code, "status": status,
|
||||
"title_ascii": _ascii_text(title),
|
||||
"title_utf8_b64": _utf8_b64(title)})
|
||||
if enqueue(conn, ev):
|
||||
emitted += 1
|
||||
last = _iso(updated)
|
||||
if rows:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute("""
|
||||
insert into events.adapter_state(adapter,cursor,updated_at)
|
||||
values ('audit360',%s,now())
|
||||
on conflict (adapter) do update
|
||||
set cursor=excluded.cursor, updated_at=now()
|
||||
""", (last,))
|
||||
conn.commit()
|
||||
return emitted
|
||||
@@ -24,6 +24,7 @@ def connect():
|
||||
dbname=os.getenv("PGDATABASE", "rag"),
|
||||
user=os.getenv("PGUSER", "postgres"),
|
||||
password=pw,
|
||||
client_encoding="UTF8",
|
||||
connect_timeout=5,
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
[Unit]
|
||||
Description=Buryans Stage 2 events pipeline
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
Environment=PYTHONPATH=/opt/events-nats
|
||||
ExecStart=/usr/bin/python3 /root/buryan-infra/ops/events/pipeline.py
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectSystem=full
|
||||
ProtectHome=read-only
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Durable Stage 2 pipeline: adapter → outbox → JetStream → idempotent consumer."""
|
||||
import asyncio
|
||||
import signal
|
||||
import time
|
||||
|
||||
from adapters import audit360
|
||||
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)
|
||||
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()
|
||||
@@ -40,6 +40,12 @@ CREATE TABLE IF NOT EXISTS events.inbox (
|
||||
CREATE INDEX IF NOT EXISTS inbox_key_idx
|
||||
ON events.inbox (idempotency_key);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS events.adapter_state (
|
||||
adapter text PRIMARY KEY,
|
||||
cursor text,
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS events.effects (
|
||||
idempotency_key text PRIMARY KEY,
|
||||
consumer text NOT NULL,
|
||||
|
||||
Reference in new issue
Block a user