Samples
Runnable samples live in the repository's
sample/ directory.
Each is a standalone npm workspace with a test script (typecheck + a smoke
run), executed on every CI run against the packed library.
00-showcase — the whole engine on SQLite
sample/00-showcase
is a small Nest application context on an in-memory better-sqlite3 database:
a UserService with a @Transactional() method, and three @JobHandler
classes exercising every outcome path.
Its smoke proves, end to end:
- Transactional enqueue —
register()inserts the user row and enqueuesemail.welcomein the same transaction; the handler's side effect (sent_emails, keyed onctx.jobIdwithON CONFLICT DO NOTHING) lands exactly once after a drain. - uniqueKey dedup — a second
welcome:<email>enqueue while the first is active returns the existing row (same id, one row in the table), and completing the job releases the key. - Delayed jobs — a
delayMs: 150job is not claimable early (tick()claims 0), then runs after its due time. - Retry-then-succeed —
report.generatethrowsRetryableError('…', 25)on attempt 1 and writes its report on attempt 2; the drain reportsretried: 1, the second draincompleted: 1, and the report row is written exactly once. - Permanent failure —
billing.chargethrowsPermanentError; the job fails in a single tick with the reason inlast_error, no retries burned. - The worker loop —
runWorkerLoop(20ms poll) picks up a job enqueued after it started, andcontroller.abort()stops it gracefully.
Run it from the repository root:
npm install
npm run build --workspace @nest-native/jobs
npm run showcase
What a sample is for
The samples pin the exact published version ("@nest-native/jobs": "0.1.0")
rather than a range — CI resolves them against the workspace before a release
and against the registry after one (release:check:published), so every
release is proven consumable by a real application before and after it ships.