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

Flask-APScheduler multiple jobs running at the same time when having multiple workers #230

Open
denisvitez opened this issue Jul 31, 2023 · 1 comment

Comments

@denisvitez
Copy link

Hi,

I'm using the Flask-APScheduler for a simple job inside my application that checks for pending notification messages and sends them. I moved the application onto the production server where I'm running it using uWSGI and multiple workers. Now the side-effect is that every worker is executing the same job, so now I have 8 workers trying to send the same email. Is there an option to configure that the job is only executed on one worker?

My job is currently configured as:

{
            'id': 'email_notification_service',
            'func': 'application.main.jobs:send_new_notifications',
            'args': (),
            'trigger': 'interval',
            'seconds': int(os.getenv('SCHEDULER_INTERVAL', 60))
}
@christopherpickering
Copy link
Collaborator

Hey Denis, that is not possible with Apscheduler v3: https://viniciuschiele.github.io/flask-apscheduler/rst/tips.html.
If you want to keep many workers in your primary app, you could run the scheduler as an independent process from your primary app and make api calls to it. Also, if your runners are doing intense jobs you could also run them in a second api process with more workers and call to it from the scheduler's runner function.

Basically:
web app (8 workers) >>>> scheduler api (1 worker) >>>> runner api (many workers)

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

No branches or pull requests

2 participants