fix: coordinate transaction reminder cron across multiple instances#820
Open
Okorie2000-code wants to merge 1 commit into
Open
Conversation
Introduces a Redis distributed lock in TransactionRemindersService so only one instance processes reminders per cron window. - CacheService.setNx: atomic SET NX EX via Redis client - sendDeadlineReminders acquires lock:transaction-reminders before processing; skips if already held - Lock released in finally block so crashes never leave stale locks - Lock TTL: 300 s (exceeds expected job runtime) - Full test coverage: lock acquired, lock unavailable, lock release, and regression tests for existing reminder behaviour Closes MettaChain#696
|
@Okorie2000-code 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! 🚀 |
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.
Summary
Prevents duplicate reminder notifications when multiple application instances run the
transaction-reminderscron job simultaneously.Coordination strategy: Redis distributed lock
sendDeadlineRemindersnow acquires a Redis lock (lock:transaction-reminders) via atomicSET NX EXbefore processing begins. Any instance that cannot acquire the lock logs a message and returns early — no reminders are sent twice.lock:transaction-remindersfinallyblock — released on both success and errorCacheService.setNxadded to the existingCacheService; no new packagesFiles changed
src/cache/cache.service.tssetNx(key, value, ttlSeconds)— atomic Redis SET NX EXsrc/transactions/transaction-reminders.service.tsprocessReminderssrc/transactions/transaction-reminders.service.spec.tssrc/transactions/transactions.module.tsCacheModuleConfigimport (already present, no change needed)Tests
Verification
Closes #696