Duplicating Startup Jobs
See original GitHub issueWhen I add jobs after flask is started (through a req to the /scheduler), it behaves correctly, but somehow I cannot seem to get apscheduler to run only one instance of a job during startup. It creates two of each job regardless of whether I have max instances set to 1. At this point, I’m not sure this is a problem with my configuration or the code itself since this phenomena occurs whether I use gevent or not as either the flask engine or the scheduler.
# construct flask app object
from flask import Flask, request, session, jsonify, url_for, render_template
app = Flask(import_name=__name__)
# initialize logging and debugging
import sys
import logging
app.logger.addHandler(logging.StreamHandler(sys.stdout))
app.logger.setLevel(logging.DEBUG)
app.config['ASSETS_DEBUG'] = False
# construct the landing page
@app.route('/')
def landing_page():
return jsonify({'status':'ok'}), 200
# construct the catchall for URLs which do not exist
@app.errorhandler(404)
def page_not_found(error):
return render_template('404.html'), 404
# construct scheduler object (with gevent processor)
from flask_apscheduler import APScheduler
from apscheduler.schedulers.gevent import GeventScheduler
gevent_scheduler = GeventScheduler()
ap_scheduler = APScheduler(scheduler=gevent_scheduler)
# add job to app scheduler
from time import time
scheduler_configs = {
'SCHEDULER_JOBS': [ {
'id': 'app.logger.debug.%s' % str(time()),
'func': 'launch:app.logger.debug',
'kwargs': { 'msg': 'APScheduler has started.' },
'misfire_grace_time': 5,
'max_instances': 1,
'replace_existing': False,
'coalesce': True
} ],
'SCHEDULER_TIMEZONE': 'UTC',
'SCHEDULER_VIEWS_ENABLED': True
}
app.config.update(**scheduler_configs)
# attach app to scheduler and start scheduler
ap_scheduler.init_app(app)
ap_scheduler.start()
# initialize test wsgi localhost server with default memory job store
if __name__ == '__main__':
from gevent.pywsgi import WSGIServer
http_server = WSGIServer(('0.0.0.0', 5001), app)
http_server.serve_forever()
# app.run(host='0.0.0.0', port=5001)
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Copy.ai Jobs | Wellfound (formerly AngelList Talent)
Copy.ai is hiring! See 5 jobs in December 2022! Apply to the latest jobs with a single profile and get in touch with...
Read more >Jobs at Replicate (W20) | Y Combinator's Work at a Startup
When starting this company, we thought: instead of getting a job at the best place to work, let's make that best place to...
Read more >Why do so many job sites duplicate the same jobs claiming ...
Everyone wants earn money, hence they usually post same jobs. What the users get is duplicated job openings. I also have observed the...
Read more >How to remove duplicate entries in Startup of SYSCONFIG???
I have duplicate entries of the following startup items in the Startup tab of System Configuration Utility, ... Good job, PJ!
Read more >How can I remove a duplicate startup entry? - Super User
Take a look with Autoruns - it might be in both a user-specific and system-wide startup location. You could also manually go through...
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
I use app.run(use_reloader=False) to prevent flask to create two instances of flask_apscheduler.APScheduler. If I omit use_reload=False jobs are also fired twice for me. See: http://stackoverflow.com/a/15491587
Separating the init from the launch did the trick. And… you make a good point about putting all the configs into an init file being better practice (especially for all these self-referential callables). Thanks!