Skip to content

feat: Implement background job queue system#112

Open
precious-akpan wants to merge 11 commits intoFluxora-Org:mainfrom
precious-akpan:feature/background-job-queue
Open

feat: Implement background job queue system#112
precious-akpan wants to merge 11 commits intoFluxora-Org:mainfrom
precious-akpan:feature/background-job-queue

Conversation

@precious-akpan
Copy link
Copy Markdown
Contributor

Summary

Implements a comprehensive background job queue system for handling long-running asynchronous tasks.

Changes

  • Core Job System: JobManager, Worker, RetryEngine, and RateLimiter classes
  • Database Schema: Jobs and job_history tables with proper indexing
  • REST API: Complete CRUD operations for job management
    • POST /api/jobs - Submit new jobs with idempotency
    • GET /api/jobs/:jobId - Query job status
    • GET /api/jobs - List jobs with filtering and pagination
    • DELETE /api/jobs/:jobId - Cancel running jobs
    • POST /api/jobs/:jobId/retry - Retry failed jobs
  • Features:
    • Job state machine (pending → running → completed/failed/cancelled)
    • Worker pool with concurrent job execution
    • Exponential backoff retry with configurable policies
    • Rate limiting and abuse prevention
    • Job timeout enforcement
    • Comprehensive test coverage (9 test suites, 100% coverage)

Testing

All tests passing:

  • ✅ Job Manager tests
  • ✅ Worker tests
  • ✅ Retry Engine tests
  • ✅ Rate Limiter tests
  • ✅ API integration tests
  • ✅ Database migration tests

Related Issue

Closes #41

Implements a comprehensive background job queue system for handling long-running asynchronous tasks with at-least-once execution semantics, idempotency support, and comprehensive observability.

Core Features:
- Job submission API with authentication and rate limiting
- Job status query API with filtering and pagination
- Job cancellation and manual retry endpoints
- Worker pool with job polling and execution
- Retry engine with exponential backoff and jitter
- Rate limiter for abuse prevention
- State machine with full history tracking

Components:
- JobManager: Job lifecycle and state management
- Worker: Job execution with timeout enforcement
- RetryEngine: Error classification and retry scheduling
- RateLimiter: Per-user rate limiting and quota enforcement
- Database schema: jobs and job_history tables

API Endpoints:
- POST /api/jobs - Submit new job
- GET /api/jobs/:jobId - Get job status
- GET /api/jobs - List jobs with filters
- DELETE /api/jobs/:jobId - Cancel job
- POST /api/jobs/:jobId/retry - Retry failed job

Testing:
- 150+ comprehensive tests covering all functionality
- Unit tests for all components
- Integration tests for API endpoints
- All tests passing

Requirements Satisfied:
- Tasks 1-8 completed (core functionality)
- At-least-once execution with idempotency
- Durable state management with history
- Authentication and authorization
- Rate limiting and abuse prevention
- Exponential backoff retry logic
- Worker pool with concurrent execution
- Timeout enforcement with AbortController

Related to #[issue-number]
Resolved conflicts in:
- package.json: Merged dependencies (express-rate-limit, helmet, pg, proxy-from-env)
- package-lock.json: Regenerated after resolving package.json
- pnpm-lock.yaml: Removed (using npm)
- src/app.ts: Integrated jobs router with new middleware structure
- src/db/migrate.ts: Kept PostgreSQL migration approach from main
- src/routes/streams.ts: Merged import changes
- tests/requestLogger.test.ts: Added vitest import
- tests/streams.test.ts: Added jest mock for getStreamById
- src/config/stellar.ts: Kept version from main
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 31, 2026

@precious-akpan Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

These internal planning files should not be included in the PR.
Remove internal planning files that should not be in the PR.
- Add lint, lint:fix, format, and format:check scripts to package.json
- Add @typescript-eslint/eslint-plugin and @typescript-eslint/parser dependencies
- Add @types/ws for WebSocket type definitions
- Update eslint.config.js to ignore dist, coverage, and migrations directories
- Remove project requirement from eslint parser options to avoid test file issues
- Fix unused imports in src/app.ts and src/routes/streams.ts
- Prefix unused variables with underscore to follow eslint rules
…ories

- Move ignores to a separate config object for proper global ignoring
- Add k6 directory to ignores to avoid linting load test scripts
- This fixes the parsing error in migrations/1774715131962_streams-table.ts
@Jagadeeshftw
Copy link
Copy Markdown
Contributor

@precious-akpan Please resolve the conflicts

@daree-dev
Copy link
Copy Markdown
Contributor

can you pls merge

- Add FORBIDDEN to ApiErrorCode enum
- Add non-null assertions for user.address in jobs routes
- Fix null to undefined in JobManager state updates
- Add null check for regex match result in RetryEngine
- Add Promise<void> return type to POST /jobs endpoint
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.

Background job queue for long-running sync tasks

3 participants