mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 05:58:53 -04:00
Add scheduled task to send scheduled notifcations.
Fix the query to fetch scheduled notifications.
This commit is contained in:
@@ -14,13 +14,14 @@ from app.dao.jobs_dao import dao_set_scheduled_jobs_to_pending, dao_get_jobs_old
|
||||
from app.dao.notifications_dao import (
|
||||
delete_notifications_created_more_than_a_week_ago,
|
||||
dao_timeout_notifications,
|
||||
is_delivery_slow_for_provider
|
||||
)
|
||||
is_delivery_slow_for_provider,
|
||||
dao_get_scheduled_notifications)
|
||||
from app.dao.provider_details_dao import (
|
||||
get_current_provider,
|
||||
dao_toggle_sms_provider
|
||||
)
|
||||
from app.dao.users_dao import delete_codes_older_created_more_than_a_day_ago
|
||||
from app.notifications.process_notifications import send_notification_to_queue
|
||||
from app.statsd_decorators import statsd
|
||||
from app.celery.tasks import process_job
|
||||
|
||||
@@ -46,6 +47,18 @@ def run_scheduled_jobs():
|
||||
raise
|
||||
|
||||
|
||||
@notify_celery.task(name='send-scheduled-notifications')
|
||||
@statsd(namespace="tasks")
|
||||
def send_scheduled_notifications():
|
||||
try:
|
||||
for notification in dao_get_scheduled_notifications():
|
||||
send_notification_to_queue(notification, notification.service.research_mode)
|
||||
|
||||
except SQLAlchemyError as e:
|
||||
current_app.logger.exception("Failed to send scheduled notifications")
|
||||
raise
|
||||
|
||||
|
||||
@notify_celery.task(name="delete-verify-codes")
|
||||
@statsd(namespace="tasks")
|
||||
def delete_verify_codes():
|
||||
|
||||
@@ -109,6 +109,11 @@ class Config(object):
|
||||
'schedule': crontab(minute=1),
|
||||
'options': {'queue': 'periodic'}
|
||||
},
|
||||
'send-scheduled-notifications': {
|
||||
'task': 'send-scheduled-notifications',
|
||||
'schedule': crontab(minute=1),
|
||||
'options': {'queue': 'periodic'}
|
||||
},
|
||||
'delete-verify-codes': {
|
||||
'task': 'delete-verify-codes',
|
||||
'schedule': timedelta(minutes=63),
|
||||
|
||||
@@ -473,6 +473,10 @@ def dao_created_scheduled_notification(scheduled_notification):
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_get_scheduled_notifications():
|
||||
scheduled_notifications = ScheduledNotification.query.filter(
|
||||
ScheduledNotification.scheduled_for < datetime.utcnow()).all()
|
||||
return scheduled_notifications
|
||||
notifications = Notification.query.join(
|
||||
ScheduledNotification
|
||||
).filter(
|
||||
ScheduledNotification.scheduled_for < datetime.utcnow(),
|
||||
Notification.status == NOTIFICATION_CREATED).all()
|
||||
|
||||
return notifications
|
||||
|
||||
Reference in New Issue
Block a user