Skip to content
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

Allow just one worker to be the background schedule leader #836

Merged
merged 4 commits into from
Jun 28, 2024

Conversation

sabaimran
Copy link
Member

In order to avoid additional load on the DB and server in production, elect only one worker to be the background schedule leader to run and execute automations. The other workers are started in a paused state, allowing them to delete and add new jobs, but not running jobs.

…iple schedulers

- Reduce the load on the DB and risk of issues on the service side by limiting the execution environment to one elected leader at a given time. This one is responsible for manging all of the execution of the jobs, though all workers are capaable of adding and removing jobs
@sabaimran sabaimran added the fix Fix something that isn't working as expected label Jun 28, 2024
src/khoj/utils/state.py Outdated Show resolved Hide resolved


@schedule.repeat(schedule.every(17).minutes)
def wakeup_scheduler():
Copy link
Member Author

Choose a reason for hiding this comment

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

Disclaimer.

I'm not actually sure if this is required, but I think the leader worker won't automatically be aware of new jobs being added to the store unless wakeup is explicitly called. There are some background operations that will trigger wakeup, but I don't think it's dependable, so this may be a good workaround.

@sabaimran sabaimran merged commit c83b8f2 into master Jun 28, 2024
7 checks passed
@sabaimran sabaimran deleted the fix/only-select-one-executor-in-distributed-env branch June 28, 2024 07:43
stevennt added a commit to stevennt/myai.abn.khoj.old.abandon that referenced this pull request Jun 28, 2024
Allow just one worker to be the background schedule leader (khoj-ai#836)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Fix something that isn't working as expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant