Skip to content

feat(jobs): queue retry and backoff policy per job type (closes #1128)#1874

Open
Dickson2015 wants to merge 1 commit into
EarnQuestOne:mainfrom
Dickson2015:feat/queue-retry-backoff-policy-1128
Open

feat(jobs): queue retry and backoff policy per job type (closes #1128)#1874
Dickson2015 wants to merge 1 commit into
EarnQuestOne:mainfrom
Dickson2015:feat/queue-retry-backoff-policy-1128

Conversation

@Dickson2015

Copy link
Copy Markdown
Contributor

Summary

Implements GitHub Issue #1128 — configurable retry and backoff policies per job type in the BullMQ queue layer.

Changes

File Change
BackEnd/src/modules/jobs/job-retry-policy.ts New — policy map, types, and utility functions
BackEnd/src/modules/jobs/jobs.constants.ts DEFAULT_JOB_OPTIONS derived from DEFAULT_RETRY_POLICY
BackEnd/src/modules/jobs/jobs.service.ts addJob() accepts optional jobType; worker routes non-retryable errors to DLQ immediately
BackEnd/src/modules/jobs/services/job-scheduler.service.ts startSchedule() and triggerScheduleNow() embed __jobType and apply per-type policy
BackEnd/test/jobs/job-retry-policy.spec.ts New — unit tests: policy lookup, backoff calc, non-retryable detection
BackEnd/test/jobs/jobs-retry-backoff.spec.ts New — integration tests: option merging, DLQ routing, precedence chain
BackEnd/docs/QUEUE_RETRY_POLICY.md New — reference documentation

Behaviour

  • Every JobType enum value has an explicit JobRetryPolicy (attempts, backoff type/delay, non-retryable error patterns, Redis retention limits).
  • Non-retryable errors (e.g. Invalid Stellar recipient address, Invalid email address, Invalid webhook URL) bypass all remaining retries and are immediately forwarded to the dead-letter queue.
  • Option precedence: caller opts > per-type policy > DEFAULT_JOB_OPTIONS.
  • Default fallback: jobs enqueued without a jobType continue to use DEFAULT_RETRY_POLICY (5 attempts, exponential 5 s).
  • Performance impact is zero at steady state (O(1) map lookup per addJob() call).

Testing

Both new spec files pass. Failures in the run output are pre-existing in unrelated modules and were present before this PR.

PASS  test/jobs/job-retry-policy.spec.ts
PASS  test/jobs/jobs-retry-backoff.spec.ts
PASS  test/jobs/job-processors.spec.ts

Documentation

See BackEnd/docs/QUEUE_RETRY_POLICY.md for per-job-type policy tables, backoff formulas, usage examples, and instructions for modifying a policy.

Closes #1128

…estOne#1128)

- Add job-retry-policy.ts with configurable retry/backoff for all 17 JobTypes
- Non-retryable error patterns (validation, bad addresses, invalid URLs) route
  directly to the dead-letter queue, bypassing remaining retries
- Backoff strategies: exponential for I/O-bound jobs, fixed for maintenance
- Attempt counts tuned by criticality: payouts=8, webhooks=7, email=6,
  analytics=3, maintenance=2, etc.
- addJob() accepts optional jobType param; per-type policy merged into
  BullMQ options with precedence: caller > policy > DEFAULT_JOB_OPTIONS
- DEFAULT_JOB_OPTIONS derived from DEFAULT_RETRY_POLICY (single source of truth)
- job-scheduler.service.ts embeds __jobType in job data and applies policy
  for both scheduled and manually triggered jobs
- Worker failed handler uses __jobType to look up policy and decide DLQ routing
- Add unit tests: job-retry-policy.spec.ts (policy, backoff, non-retryable)
- Add integration tests: jobs-retry-backoff.spec.ts (option merging, DLQ routing)
- Add BackEnd/docs/QUEUE_RETRY_POLICY.md with full reference documentation

Closes EarnQuestOne#1128
@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Great job so far

There’s just two blockers — the workflow is failing and merge conflict. Could you take a look and fix it so all checks pass?
You could pull from the main to get the changes before pushing.

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.

[BE-101] Add queue retry/backoff policy per job type with tests

2 participants