Skip to content

Feat #35: event-driven worker queue with Redis-backed job processing#54

Merged
Mosss-OS merged 1 commit into
mainfrom
feat/worker-queue
May 16, 2026
Merged

Feat #35: event-driven worker queue with Redis-backed job processing#54
Mosss-OS merged 1 commit into
mainfrom
feat/worker-queue

Conversation

@Mosss-OS

Copy link
Copy Markdown
Owner

Summary

  • Redis sorted-set backed job queue with priority ordering by scheduledAt timestamp
  • 5 job types: evaluate_bounty, execute_task, process_payment, match_agent, settle_bounty — each with an async handler
  • Exponential backoff retry: 2^attempt * 5s delay, capped at 120s, max 3 attempts before dead letter
  • Cron worker: GET /api/cron/worker processes 10 jobs per invocation, protected by CRON_SECRET or Vercel Cron UA
  • SSE status: GET /api/queue/status streams real-time queue depth + job lists
  • Added */1 * * * * cron schedule to vercel.json
  • 9 unit tests covering enqueue, dequeue, completion, retry with backoff, dead letter, and empty-queue edge cases

- Create app/lib/queue/ with types, queue operations, and job handlers
- Redis sorted-set queue with priority ordering by scheduledAt
- Exponential backoff retry (2^attempt * 5s, capped at 120s)
- Dead letter queue after 3 failed attempts
- Job types: evaluate_bounty, execute_task, process_payment, match_agent, settle_bounty
- Cron worker endpoint (GET /api/cron/worker) processing 10 jobs per run
- SSE status endpoint (GET /api/queue/status) for real-time monitoring
- Add * * * * * cron schedule to vercel.json
- 9 new unit tests for queue operations
@vercel

vercel Bot commented May 16, 2026

Copy link
Copy Markdown

Deployment failed with the following error:

Hobby accounts are limited to daily cron jobs. This cron expression (*/5 * * * *) would run more than once per day. Upgrade to the Pro plan to unlock all Cron Jobs features on Vercel.

Learn More: https://vercel.link/3Fpeeb1

@Mosss-OS Mosss-OS merged commit 60fd6cc into main May 16, 2026
2 of 3 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dde8c7843c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +10 to +12
const isCron = req.headers.get('user-agent')?.includes('Vercel Cron');
const isAuthed = secret && auth === `Bearer ${secret}`;
if (!isCron && !isAuthed) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Require unforgeable cron auth header

Using user-agent as a trust signal allows any external caller to spoof Vercel Cron and run the worker without the shared secret, which can execute queued jobs (including payment-related handlers) on demand. This route should only trust a verifiable signal (for example authorization or a platform-provided cron header) before processing jobs.

Useful? React with 👍 / 👎.

Comment thread app/lib/queue/queue.ts
Comment on lines +29 to +32
const results = await redis.zrange(JOB_QUEUE_KEY + ':order', 0, now, { byScore: true, count: 1, offset: 0 });
if (!results || results.length === 0) return null;
const jobId = results[0] as string;
const jobData = await redis.hget(JOB_QUEUE_KEY, jobId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Claim and remove jobs atomically when dequeuing

The dequeue path reads the next ID via zrange and then marks the hash entry as processing, but does not atomically remove/claim the sorted-set member in the same operation. Concurrent worker invocations can therefore read the same job ID before either completes, causing duplicate execution (e.g., repeated task execution or payment processing).

Useful? React with 👍 / 👎.

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.

1 participant