Skip to content

feat: Add NatsTaskProvider for NATS JetStream task queue support#181

Merged
jaredwray merged 7 commits intomainfrom
claude/add-rabbitmq-tasks-sZ13o
Apr 4, 2026
Merged

feat: Add NatsTaskProvider for NATS JetStream task queue support#181
jaredwray merged 7 commits intomainfrom
claude/add-rabbitmq-tasks-sZ13o

Conversation

@jaredwray
Copy link
Copy Markdown
Owner

What kind of change does this PR introduce?

Feature - Adds a complete task queue provider implementation using NATS JetStream.

Description

This PR introduces NatsTaskProvider, a new task queue provider that leverages NATS JetStream for reliable, distributed task processing. The implementation includes:

Key Features

  • Task Enqueueing: Publish tasks to named queues with auto-generated IDs and timestamps
  • Task Dequeueing: Register handlers to process tasks from queues with automatic consumer management
  • Acknowledgment & Rejection: Explicit task acknowledgment with auto-ack on successful completion, and rejection with optional requeue
  • Retry Logic: Configurable retry attempts with automatic requeue on failure
  • Dead-Letter Queue: Tasks exceeding max retries are moved to a dead-letter queue for inspection
  • Task Timeout: Configurable per-task and provider-level timeouts with automatic rejection on expiration
  • Deadline Extension: Handlers can extend task deadlines during processing via context.extend()
  • Multiple Handlers: Support for multiple handlers per queue with broadcast delivery
  • Queue Statistics: Real-time stats on waiting, processing, and dead-letter tasks
  • Event Emission: Extends Hookified for error event emission and lifecycle hooks

Implementation Details

  • Uses NATS JetStream streams with workqueue retention for reliable delivery
  • Implements explicit acknowledgment policy for at-least-once semantics
  • Maintains in-memory attempt tracking and processing state
  • Provides stream and consumer auto-initialization
  • Includes comprehensive cleanup on disconnect

Testing

Added 1,100+ lines of comprehensive test coverage including:

  • Constructor and initialization tests
  • Enqueue/dequeue operations
  • Task acknowledgment and rejection flows
  • Retry and dead-letter queue behavior
  • Timeout and deadline extension
  • Multiple handlers and queues
  • Edge cases and error scenarios
  • Queue statistics and cleanup

All tests pass with 100% code coverage.

Dependencies

  • Added @nats-io/jetstream for JetStream API
  • Added hookified for event emission capabilities
  • Updated docker-compose to enable JetStream mode (-js flag)

Checklist

  • Followed the Contributing and Code of Conduct guidelines
  • Tests for the changes have been added with 100% code coverage

https://claude.ai/code/session_01K5qptQLf7N1CiGemKUwKkG

Add NatsTaskProvider implementing the TaskProvider interface using NATS
JetStream for reliable task queue processing with acknowledgment,
retries, timeouts, and dead-letter queues. Enable JetStream in
docker-compose for NATS service.

https://claude.ai/code/session_01K5qptQLf7N1CiGemKUwKkG
@jaredwray jaredwray changed the title Add NatsTaskProvider for NATS JetStream task queue support feat: Add NatsTaskProvider for NATS JetStream task queue support Mar 31, 2026
Comment thread packages/nats/src/task.ts Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (10eb7c8) to head (03c7ad3).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##              main      #181    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files            9        10     +1     
  Lines         1034      1266   +232     
  Branches       200       231    +31     
==========================================
+ Hits          1034      1266   +232     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a NATS JetStream-based task provider for the qified library, enabling reliable task processing with support for retries, dead-letter queues, and timeouts. While the implementation provides a solid foundation, the review identifies several critical areas for improvement to ensure scalability and reliability in distributed environments. Key feedback includes leveraging native JetStream features for retry tracking and task extensions instead of in-memory state, adding error handling to the consumer loop to prevent crashes from malformed messages, and optimizing the retrieval of dead-letter tasks and consumer concurrency settings.

Comment thread packages/nats/src/task.ts Outdated
Comment thread packages/nats/src/task.ts Outdated
Comment thread packages/nats/src/task.ts Outdated
Comment thread packages/nats/src/task.ts
Comment thread packages/nats/src/task.ts Outdated
Comment thread packages/nats/src/task.ts
Copy link
Copy Markdown

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

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: ebdaa95414

ℹ️ 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 thread packages/nats/src/task.ts
Comment thread packages/nats/src/task.ts
Comment thread packages/nats/src/task.ts Outdated
claude and others added 5 commits April 2, 2026 00:23
- Use msg.nak() instead of msg.term() on shutdown to preserve tasks
- Use msg.working() in extend() for JetStream-native deadline extension
- Wrap JSON.parse in try-catch to prevent consumer crash on malformed messages
- Hex-encode special chars in stream/consumer names to prevent collisions
- Scope clearQueue attempt cleanup to the specific queue only
- Add test for queue names with special characters
- Achieve 100% line coverage

https://claude.ai/code/session_01K5qptQLf7N1CiGemKUwKkG
…memory attempt counts

Replace the in-memory _attemptCounts map with msg.info.deliveryCount from
JetStream. This makes retry tracking correct across multiple provider
instances in distributed deployments. Also switches from republishing
for retries to msg.nak() which lets JetStream handle redelivery natively.

https://claude.ai/code/session_01K5qptQLf7N1CiGemKUwKkG
@jaredwray jaredwray merged commit f481244 into main Apr 4, 2026
9 checks passed
@jaredwray jaredwray deleted the claude/add-rabbitmq-tasks-sZ13o branch April 4, 2026 20:12
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