feat(jobs): add idempotency keys for payout-triggering jobs (BE-103)#1873
Open
edrizxabdulganiyu-blip wants to merge 2 commits into
Open
Conversation
- Add JobIdempotencyService wrapping IdempotencyService with job-specific
checkAndLock / complete / release methods
- Idempotency key schema: payout-job:{payoutId}:{jobType} (deterministic)
- Update PayoutProcessor to check idempotency before executing; returns
cached result on duplicate and releases lock on failure
- Register PAYOUTS queue in JobsService.onModuleInit() and wire
PayoutProcessor as the queue worker
- Add IdempotencyKey entity and IdempotencyService to JobsModule providers
so the jobs layer owns its idempotency infrastructure without circular deps
- Add unit tests: job-idempotency.service.spec.ts (new)
- Update job-processors.spec.ts with JobIdempotencyService mock
|
@edrizxabdulganiyu-blip 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! 🚀 |
Contributor
|
Kindly resolve conflict |
Contributor
|
Great job so far There’s just one blocker — the workflow is failing. Could you take a look and fix it so all checks pass? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(jobs): Add idempotency keys for payout-triggering jobs (BE-103)
Summary
Implements job-level idempotency for payout-triggering BullMQ jobs to prevent duplicate Stellar
payment submissions when a job is retried or accidentally enqueued more than once.
Problem
The PayoutProcessor had no idempotency guard — if BullMQ retried a job or the scheduler
enqueued the same payoutId twice, the Stellar payment could be submitted multiple times. The
existing IdempotencyService only covered HTTP-layer POST requests via an interceptor, leaving
the job queue unprotected.
Solution
Introduced a JobIdempotencyService that reuses the existing idempotency_keys table and
IdempotencyService with job-specific semantics:
Key schema: payout-job:{payoutId}:{jobType} — deterministic, based solely on the payout record
and job type.
Lifecycle:
or a lock is held (skip duplicate). If neither, atomically acquire the lock.
replay the same output.
Changes
┌──────┬────────┐
│ File │ Change │
├──────────────────────────────────────────┼────────────────────────────────────────────────┤
│ jobs/services/job-idempotency.service.ts │ New service — job-specific idempotency wrapper │
├──────────────────────────────────────────┼────────────────────────────────────────────────┤
│ jobs/processors/payout.processor.ts │ Idempotency check before processing; │
│ │ deterministic transactionHash │
├──────────────────────────────────────────┼────────────────────────────────────────────────┤
│ jobs/jobs.module.ts │ Adds IdempotencyKey entity, │
│ │ IdempotencyService, JobIdempotencyService as │
│ │ providers │
├──────────────────────────────────────────┼────────────────────────────────────────────────┤
│ jobs/jobs.service.ts │ Registers PAYOUTS queue; wires PayoutProcessor │
│ jobs/jobs.service.ts │ Registers PAYOUTS queue; wires │
│ │ PayoutProcessor as the queue worker │
├───────────────────────────────────────────┼───────────────────────────────────────────────┤
│ test/jobs/job-idempotency.service.spec.ts │ New unit tests for all idempotency paths │
├───────────────────────────────────────────┼───────────────────────────────────────────────┤
│ test/jobs/job-processors.spec.ts │ Updated with JobIdempotencyService mock │
└───────────────────────────────────────────┴───────────────────────────────────────────────┘
Test Coverage
Notes
1800000000004.
directly rather than importing PayoutsModule.
close #1130