Allow for the disabling of scheduled tasks in the configuration. Default to false.

This commit is contained in:
Dan 2020-10-12 13:42:41 -04:00
parent cb4bec7190
commit b89d2729fa
2 changed files with 7 additions and 3 deletions

View File

@ -9,13 +9,16 @@ from communicator.api import admin
def update_and_notify():
with app.app_context():
admin.update_and_notify()
if app.config['RUN_SCHEDULED_TASKS']:
admin.update_and_notify()
else:
app.logger.info("Currently not running scheduled tasks RUN_SCHEDULED_TASKS"
" is set to false in configuration.")
scheduler = BackgroundScheduler()
scheduler.add_jobstore('sqlalchemy', url=db.engine.url)
scheduler.add_job(
update_and_notify, 'interval', minutes=app.config['SCHEDULED_TASK_MINUTES'],
# update_and_notify, 'interval', seconds=5,
id='update_data', replace_existing=True
)

View File

@ -75,4 +75,5 @@ TWILIO_NUMBER = environ.get('TWILIO_NUMBER')
FIRESTORE_JSON = environ.get('FIRESTORE_JSON')
# Scheduled tasks
SCHEDULED_TASK_MINUTES = float(environ.get('SCHEDULED_TASK_MINUTES', default=10))
SCHEDULED_TASK_MINUTES = float(environ.get('SCHEDULED_TASK_MINUTES', default=1))
RUN_SCHEDULED_TASKS = environ.get('RUN_SCHEDULED_TASKS', default="false") == "true"