gunicorn duplicating scheduler jobs
See original GitHub issueHave a process in my flask app that refreshes data in a db every hour, works fine in Dev, but once I move to prod gunicorn, on startup the jobs get added multiple times… Did some research and came across this article, but not sure how I can pass the --preload
flag to this through docker compose:
https://stackoverflow.com/questions/16053364/make-sure-only-one-worker-launches-the-apscheduler-event-in-a-pyramid-web-app-ru
Python code:
# Set cron job to pull data every hour
with app.app_context():
try:
scheduler = BackgroundScheduler()
scheduler.add_job(func=refresh_database, trigger="cron", hour='*')
dash_app.server.logger.info('Starting cron jobs')
scheduler.start()
except BaseException as e:
dash_app.server.logger.error('Error starting cron jobs: {}'.format(e))
if __name__ == '__main__':
dash_app.run_server(host='0.0.0.0', debug=False, port=80, ssl_context=('/keys/cert.crt', '/keys/certkey'))
Docker Compose:
fitly:
build:
context: ./dockercontrol-master
dockerfile: fitly-dockerfile
container_name: fitly
restart: always
depends_on:
- mariadb
- letsencrypt
ports:
- "8050:80"
environment:
- MODULE_NAME=index
- VARIABLE_NAME=app
- TZ=America/New_York
- PUID=1001
- PGID=100
volumes:
- /share/CACHEDEV2_DATA/Container/Fitly/config.ini:/app/config.ini
- /share/CACHEDEV2_DATA/Container/Fitly/log.log:/app/log.log
- /share/CACHEDEV2_DATA/Container/LetsEncrypt/keys:/app/keys
Also…If there is a better approach then what I am trying to do above, please share!
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Dealing with Gunicorn workers duplicating scheduled tasks
The problem is that Gunicorn uses 3 workers and when I run the app, the Apscheduler job also getting duplicated 3 times. This...
Read more >Running ApScheduler in Gunicorn Without Duplicating Per ...
I have gunicorn running my app with 5 workers. I have a data structure that all the workers need access to that is...
Read more >How To Serve Flask Applications with Gunicorn and Nginx on ...
In this guide, you will build a Python application using the Flask microframework on Ubuntu 18.04. The bulk of this article will be...
Read more >Design — Gunicorn 20.1.0 documentation
It manages the list of running workers by listening for signals like TTIN, TTOU, and CHLD. TTIN and TTOU tell the master to...
Read more >Securely Deploy a Django App With Gunicorn, Nginx, & HTTPS
Putting Your Site Online With Django, Gunicorn, and Nginx ... jobs -l [1]+ 43689 Running nohup python manage.py runserver & $ kill 43689...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks @mtik00! Got it working with the following (didn’t need the
=True
portion):Thanks for the help here @mtik00 ! 👏 🙇
Thanks for reporting back and closing the issue @ethanopp 👍