Issue 21 — event infrastructure: - NormalizedEvent<T> + payload types in packages/shared-types/src/events/ - Bus.onPublish() hook for side-effect bridges - NATS JetStream adapter (services/api/src/events/nats.ts): connects when NATS_URL is set, creates signals.> and feedback.> streams, bridges all in-process bus publishes to JetStream — no-ops gracefully when NATS is absent - NATS service added to docker-compose (profile: events|full, port 4222/8222) Issue 22 — Todoist background sync: - services/api/src/signals/scheduler.ts: queries all active-token users every 15 min (TODOIST_SYNC_INTERVAL_MS), fan-out via todoistSource.fetchSignals() which emits signals.task.synced; on-demand fetch remains as freshness fallback - NATS_URL + TODOIST_SYNC_INTERVAL_MS added to config Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -69,6 +69,12 @@ const RING_SIZE = 500;
|
||||
class Bus extends EventEmitter {
|
||||
private ring: StoredEvent[] = [];
|
||||
private seq = 0;
|
||||
private publishHooks: Array<(subject: string, payload: unknown) => void> = [];
|
||||
|
||||
/** Register a side-effect hook called on every publish (e.g. NATS bridge) */
|
||||
onPublish(hook: (subject: string, payload: unknown) => void): void {
|
||||
this.publishHooks.push(hook);
|
||||
}
|
||||
|
||||
publish<K extends keyof EventMap>(subject: K, payload: EventMap[K]): void {
|
||||
const entry: StoredEvent = {
|
||||
@@ -80,6 +86,7 @@ class Bus extends EventEmitter {
|
||||
if (this.ring.length >= RING_SIZE) this.ring.shift();
|
||||
this.ring.push(entry);
|
||||
this.emit(subject, payload);
|
||||
for (const hook of this.publishHooks) hook(subject, payload);
|
||||
}
|
||||
|
||||
subscribe<K extends keyof EventMap>(subject: K, handler: (payload: EventMap[K]) => void): void {
|
||||
|
||||
Reference in New Issue
Block a user