Skip to content

Implement Redis-based leader election for background jobs - #108

Open
Achievers-sketch wants to merge 1 commit into
SmartDropLabs:mainfrom
Achievers-sketch:main
Open

Implement Redis-based leader election for background jobs#108
Achievers-sketch wants to merge 1 commit into
SmartDropLabs:mainfrom
Achievers-sketch:main

Conversation

@Achievers-sketch

Copy link
Copy Markdown

Closes #98

  • Added leader election mechanism using Redis to ensure only one instance runs scheduled jobs at a time.
  • Created src/services/leaderElection.js for managing leader lease acquisition, renewal, and release.
  • Introduced src/jobs/leaderAwareJob.js to wrap existing jobs with leader election logic.
  • Updated src/index.js to utilize wrapped jobs for price refresh, webhook retry, and airdrop expiry.
  • Enhanced health check endpoint to report leadership status for each job.
  • Added configuration options for instance ID, lease TTL, and renewal interval in src/config.js.
  • Documented leader election mechanism and configuration in README.md.
  • Created comprehensive tests for leader election functionality in test/leaderElection.test.js.

- Added leader election mechanism using Redis to ensure only one instance runs scheduled jobs at a time.
- Created `src/services/leaderElection.js` for managing leader lease acquisition, renewal, and release.
- Introduced `src/jobs/leaderAwareJob.js` to wrap existing jobs with leader election logic.
- Updated `src/index.js` to utilize wrapped jobs for price refresh, webhook retry, and airdrop expiry.
- Enhanced health check endpoint to report leadership status for each job.
- Added configuration options for instance ID, lease TTL, and renewal interval in `src/config.js`.
- Documented leader election mechanism and configuration in `README.md`.
- Created comprehensive tests for leader election functionality in `test/leaderElection.test.js`.
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 jobs (price refresh, webhook retry worker) have no leader election — every horizontally-scaled replica runs them independently

1 participant