Skip to content

feat: worker-kit 0.1.0, background jobs on BullMQ or in-process - #1

Merged
BackStacked merged 1 commit into
mainfrom
claude/project-thread-4woo44
Oct 15, 2026
Merged

BackStacked merged 1 commit into
mainfrom
claude/project-thread-4woo44

Conversation

@BackStacked

Copy link
Copy Markdown
Contributor

Requested by Himanshu · project thread

Before: the Redis + BullMQ worker lived inside the api (src/jobs/), hard-wired to its two queues, and mail-kit had its own BullMQ-shaped adapter. Nothing else could reuse it.

After: @mgpl-diagnostics/worker-kit is its own kit. You define a job once (defineJob) and start it through one queue API (createJobQueue) on any of three backends: BullMQ on Redis (/bullmq entry, with startWorker for the worker process), in-process (inlineBackend), or the worker when Redis is up and standalone otherwise (fallbackBackend). jobs.enqueuer(job) has mail-kit's MailQueue shape.

The three backends behave the same: data and results cross JSON, retries and exponential backoff match BullMQ, and only a JobFailure's message is shown (anything else reads "Job failed" and goes to onError). Job data is checked in the caller: JSON only, a size limit, and no secret-looking keys (token, password, secret, …).

How: the behaviour is lifted from the api's src/jobs/bullmq.ts and inline.ts (UUID job ids, UnrecoverableError for non-retryable failures, retention via removeOnComplete / removeOnFail, the state mapping) and generalised to any job set. scripts/test.ts runs one scenario (success with Dates, a job that succeeds on attempt 3, a non-retryable failure, an internal crash) on the in-process backend and on BullMQ against a real Redis and asserts identical results. CI runs a Redis service with REQUIRE_REDIS=1, and checks that dist/index.js does not import bullmq or ioredis. Same layout as the other kits (tsup, tsx tests, ci job id, publish.yml on v* tags, dependabot, CODEOWNERS, llms files).

Locally: npm run typecheck && npm test && npm run build → 30 passed, 0 failed.

Follow-ups (not in this PR): switch the api's src/jobs onto worker-kit once 0.1.0 is published, and add worker-kit to CHECKS in .github/scripts/protect-repos.mjs.

🤖 Generated with Claude Code

https://claude.ai/code/session_019ksSjXhGjrz5w5b9THeNDT


Generated by Claude Code

Typed job definitions, one queue API over BullMQ on Redis, in-process, or
worker-when-available-else-standalone, and the worker runner. Extracted from the
api's src/jobs so the api and mail-kit share one job layer. The same scenario runs
on the in-process backend and on BullMQ against a real Redis and must match.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ksSjXhGjrz5w5b9THeNDT
@BackStacked BackStacked self-assigned this Oct 15, 2026
@BackStacked
BackStacked merged commit 6ba1d70 into main Oct 15, 2026
1 check passed
BackStacked added a commit to mgpl-diagnostics/.github that referenced this pull request Oct 15, 2026
<!-- claude-projects-attribution: {"github_login":"BackStacked"} -->
_Requested by **Himanshu** · [project
thread](https://claude.ai/code/project/chan_016JXeBZ2UxSi4N5VU2C26fQ?thread=cmsg_016JXeBZ2UxSi4N5VU2C26fQD1q5wdig6xLugjBA7ckTBv)_

## What and why

Before: `scripts/protect-repos.mjs` had no entry for the new worker-kit
repo, so protecting it would not require the `ci` check, and the org
profile did not list it.

After: `"worker-kit": ["ci"]` is in `CHECKS`, and the profile has a
worker-kit card after mail-kit. The kit itself is
mgpl-diagnostics/worker-kit#1. Once this is merged, the owner's local
agent runs `node scripts/protect-repos.mjs worker-kit`.

## Type

- [ ] Bug fix
- [ ] Feature
- [ ] Test data (ranges, units, prices) — source linked below
- [x] Docs
- [x] Refactor / tooling

## Checklist

- [x] Opened on a branch (not `main`)
- [x] `node --check scripts/protect-repos.mjs` passes (this repo has no
typecheck or tests)
- [x] Docs updated (profile README)
- [x] **No real patient data, contact details or signatures**

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_019ksSjXhGjrz5w5b9THeNDT

---
_Generated by [Claude
Code](https://claude.ai/code/session_019ksSjXhGjrz5w5b9THeNDT)_

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants