Skip to content

Leader election implementation #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

thoven87
Copy link
Contributor

@thoven87 thoven87 commented May 3, 2025

  • Leader election implementation
  • Right now it's only used to prevent multiple workers (CRON) from enqueuing a job more than once

* Leader election implementation
* Right now it's only used to prevent multiple workers (CRON) from enqueuing a job more than once
@@ -576,6 +611,8 @@ extension PostgresJobQueue {
if self.queue.isStopped.withLockedValue({ $0 }) {
return nil
}
// The first node to aquire the lock will be the leader
try await queue.electAsLeader()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to be calling this every time we are popping a job off the queue (something that can be called 100s of times a second), or should we be calling this when a job is ready to schedule.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to be calling this every time we are popping a job off the queue (something that can be called 100s of times a second), or should we be calling this when a job is ready to schedule.

Since we're using the Bully algorithm, we do want to try to elect a leader as fast as possible. Since we only need the election process for just the scheduler as now, it might be worth trying to elect a leader when the scheduler is about to schedule a job.

@thoven87 thoven87 closed this May 5, 2025
@thoven87 thoven87 deleted the leader-election branch May 5, 2025 22:58
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.

2 participants