@021.is/spine-jobs
v0.4.3
Published
NATS JetStream publisher + consumer wrapper. Async fan-out + cron triggers + work queues, all going through your NATS instance.
Readme
@021.is/spine-jobs
Wrapper around NATS JetStream (your NATS instance).
Three uses:
- Async fan-out — a publisher emits
event.published; independent consumers (audit, analytics, push) each handle it. No HTTP, no waiting, no fragile orchestration. - Cron triggers —
spine.cron.daily-billing-runpublished by a tiny scheduler pod; the billing service consumes. - Work queues — long-running jobs (image processing, batch emails) get enqueued; consumers pick them up at their own pace.
Use
import { connectJobs } from "@021.is/spine-jobs";
const jobs = await connectJobs({ servers: env.NATS_URL });
// Publish
await jobs.publish("event.published", { eventId: "e_1", organizerId: "o_1" });
// Consume (one consumer per concern; durable so it survives restarts)
await jobs.consume("event.published", "audit-consumer", async (payload) => {
await db.audit.create({ data: { action: "event.published", ...payload } });
});Tests
JetStream-dependent — gated by a Testcontainers NATS image when added to the test suite. For now, integration tests live in the consuming repos.
