mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Add pending flag to scheduled_notifications.
Set pending flag to false when the notification has been sent to provider task.
This commit is contained in:
@@ -15,8 +15,8 @@ from app.dao.notifications_dao import (
|
||||
delete_notifications_created_more_than_a_week_ago,
|
||||
dao_timeout_notifications,
|
||||
is_delivery_slow_for_provider,
|
||||
dao_get_scheduled_notifications
|
||||
)
|
||||
dao_get_scheduled_notifications,
|
||||
set_scheduled_notification_to_processed)
|
||||
from app.dao.statistics_dao import dao_timeout_job_statistics
|
||||
from app.dao.provider_details_dao import (
|
||||
get_current_provider,
|
||||
@@ -56,6 +56,7 @@ def send_scheduled_notifications():
|
||||
scheduled_notifications = dao_get_scheduled_notifications()
|
||||
for notification in scheduled_notifications:
|
||||
send_notification_to_queue(notification, notification.service.research_mode)
|
||||
set_scheduled_notification_to_processed(notification.id)
|
||||
current_app.logger.info(
|
||||
"Sent {} scheudled notifications to the provider queue".format(len(scheduled_notifications)))
|
||||
except SQLAlchemyError as e:
|
||||
|
||||
@@ -477,6 +477,14 @@ def dao_get_scheduled_notifications():
|
||||
ScheduledNotification
|
||||
).filter(
|
||||
ScheduledNotification.scheduled_for < datetime.utcnow(),
|
||||
Notification.status == NOTIFICATION_CREATED).all()
|
||||
ScheduledNotification.pending).all()
|
||||
|
||||
return notifications
|
||||
|
||||
|
||||
def set_scheduled_notification_to_processed(notification_id):
|
||||
ScheduledNotification.query.filter(
|
||||
ScheduledNotification.notification_id == notification_id
|
||||
).update(
|
||||
{'pending': False}
|
||||
)
|
||||
|
||||
@@ -958,6 +958,7 @@ class ScheduledNotification(db.Model):
|
||||
notification_id = db.Column(UUID(as_uuid=True), db.ForeignKey('notifications.id'), index=True, nullable=False)
|
||||
notification = db.relationship('Notification', uselist=False)
|
||||
scheduled_for = db.Column(db.DateTime, index=False, nullable=False)
|
||||
pending = db.Column(db.Boolean, nullable=False, default=True)
|
||||
|
||||
|
||||
class InvitedUser(db.Model):
|
||||
|
||||
Reference in New Issue
Block a user