Changed to send reminders daily until completed. Added check to limit notifications from going out once per day. Added second scheduler task to reset notification sent status 1 hour after they are sent.

This commit is contained in:
dan
2022-02-19 23:27:19 -05:00
parent 45bb2f4252
commit a68f8f68ed

33
app.py
View File

@@ -8,7 +8,9 @@ from flask_apscheduler import APScheduler
# Set to True to simplify testing
TESTING = False
notificationHour = 10
textSent = False
emailSent = False
class Config:
SCHEDULER_API_ENABLED = True
@@ -63,39 +65,56 @@ SettingsMetadata.__table__.create(bind=engine, checkfirst=True)
Session = sessionmaker(bind=engine)
@scheduler.task('cron', id='send_notifications', hour='10')
@scheduler.task('cron', id='send_notifications', hour=notificationHour)
def Checknotifications():
session = Session()
global textSent
global emailSent
nextFeed = session.query(Dates).filter_by(dateTypeID=3).first().dateValue
nextClean = session.query(Dates).filter_by(dateTypeID=5).first().dateValue
clean = False
today = datetime.date.today()
if nextClean == today or TESTING is True:
if nextClean <= today or TESTING is True:
clean = True
else:
clean = False
# Check if notififcations need to be sent out
if nextFeed == today or TESTING is True:
# Check if notifications need to be sent out
if nextFeed <= today or TESTING is True:
# Check what notifications should be sent out grab the grab relevant contact info and pass it to the appropriate
# notification method
notifications = {'text': session.query(Settings).filter_by(settingType=1).first().settingValue,
'email': session.query(Settings).filter_by(settingType=2).first().settingValue}
if notifications['text']:
if notifications['text'] and textSent is False:
contact = session.query(Settings).filter_by(settingType=4).first().settingValue
sendNotifications.sendText(contact, clean)
if notifications['email']:
textSent = True
if notifications['email'] and emailSent is False:
contact = session.query(Settings).filter_by(settingType=5).first().settingValue
sendNotifications.sendEmail(contact, clean)
print('sent any selected notifications')
# print(today)
# print(nextFeed)
if TESTING is True:
resetNotifcations()
else:
print('Not time to Send')
session.close()
@scheduler.task('cron', id='reset_notifications', hour=notificationHour+1)
def resetNotifcations():
global textSent
global emailSent
if textSent is True:
textSent = False
if emailSent is True:
emailSent = False
return
scheduler.start()
# If in testing mode reschedule the notification check to run every minute