throttle notifications so we don't run afoul of the email and text message servers.

This commit is contained in:
Dan Funk 2020-09-25 11:51:17 -04:00
parent 2fe87b1cf9
commit 7b4cbe4c24
2 changed files with 4 additions and 0 deletions

View File

@ -4,6 +4,7 @@ from communicator.models.notification import Notification, EMAIL_TYPE, TEXT_TYPE
from communicator.services.ivy_service import IvyService
from communicator.services.notification_service import NotificationService
from communicator.services.sample_service import SampleService
from time import sleep
def status():
@ -53,6 +54,7 @@ def notify_by_email():
except Exception as e:
db.session.add(Notification(type=EMAIL_TYPE, sample=sample, successful=False,
error_message=str(e)))
sleep(0.5)
def notify_by_text():
"""Sends out notifications via SMS Message, but only at reasonable times of day"""
@ -73,6 +75,7 @@ def notify_by_text():
except Exception as e:
db.session.add(Notification(type=TEXT_TYPE, sample=sample, successful=False,
error_message=str(e)))
sleep(0.5)

View File

@ -15,6 +15,7 @@ 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
)