def timeout_notifications(): ( technical_failure_notifications, temporary_failure_notifications, ) = dao_timeout_notifications( current_app.config.get("SENDING_NOTIFICATIONS_TIMEOUT_PERIOD")) notifications = technical_failure_notifications + temporary_failure_notifications for notification in notifications: # queue callback task only if the service_callback_api exists service_callback_api = get_service_delivery_status_callback_api_for_service( service_id=notification.service_id) if service_callback_api: encrypted_notification = create_delivery_status_callback_data( notification, service_callback_api) send_delivery_status_to_service.apply_async( [str(notification.id), encrypted_notification], queue=QueueNames.CALLBACKS, ) current_app.logger.info( "Timeout period reached for {} notifications, status has been updated." .format(len(notifications))) if technical_failure_notifications: message = ( "{} notifications have been updated to technical-failure because they " "have timed out and are still in created.Notification ids: {}". format( len(technical_failure_notifications), [str(x.id) for x in technical_failure_notifications], )) raise NotificationTechnicalFailureException(message)
def timeout_notifications(): technical_failure_notifications, temporary_failure_notifications = \ dao_timeout_notifications(current_app.config.get('SENDING_NOTIFICATIONS_TIMEOUT_PERIOD')) notifications = technical_failure_notifications + temporary_failure_notifications for notification in notifications: check_for_callback_and_send_delivery_status_to_service(notification) current_app.logger.info( "Timeout period reached for {} notifications, status has been updated." .format(len(notifications))) if technical_failure_notifications: message = "{} notifications have been updated to technical-failure because they " \ "have timed out and are still in created.Notification ids: {}".format( len(technical_failure_notifications), [str(x.id) for x in technical_failure_notifications]) raise NotificationTechnicalFailureException(message)
def test_dao_timeout_notifications_only_updates_for_older_notifications(notify_db, notify_db_session): with freeze_time(datetime.utcnow() + timedelta(minutes=10)): created = sample_notification(notify_db, notify_db_session, status='created') sending = sample_notification(notify_db, notify_db_session, status='sending') pending = sample_notification(notify_db, notify_db_session, status='pending') delivered = sample_notification(notify_db, notify_db_session, status='delivered') assert Notification.query.get(created.id).status == 'created' assert Notification.query.get(sending.id).status == 'sending' assert Notification.query.get(pending.id).status == 'pending' assert Notification.query.get(delivered.id).status == 'delivered' updated = dao_timeout_notifications(1) assert NotificationHistory.query.get(created.id).status == 'created' assert NotificationHistory.query.get(sending.id).status == 'sending' assert NotificationHistory.query.get(pending.id).status == 'pending' assert NotificationHistory.query.get(delivered.id).status == 'delivered' assert updated == 0
def test_dao_timeout_notifications(notify_db, notify_db_session, ): with freeze_time(datetime.utcnow() - timedelta(minutes=2)): created = sample_notification(notify_db, notify_db_session, status='created') sending = sample_notification(notify_db, notify_db_session, status='sending') pending = sample_notification(notify_db, notify_db_session, status='pending') delivered = sample_notification(notify_db, notify_db_session, status='delivered') assert Notification.query.get(created.id).status == 'created' assert Notification.query.get(sending.id).status == 'sending' assert Notification.query.get(pending.id).status == 'pending' assert Notification.query.get(delivered.id).status == 'delivered' updated = dao_timeout_notifications(1) assert Notification.query.get(created.id).status == 'technical-failure' assert Notification.query.get(sending.id).status == 'temporary-failure' assert Notification.query.get(pending.id).status == 'temporary-failure' assert Notification.query.get(delivered.id).status == 'delivered' assert NotificationHistory.query.get(created.id).status == 'technical-failure' assert NotificationHistory.query.get(sending.id).status == 'temporary-failure' assert NotificationHistory.query.get(pending.id).status == 'temporary-failure' assert NotificationHistory.query.get(delivered.id).status == 'delivered' assert updated == 3
def timeout_notifications(): updated = dao_timeout_notifications(current_app.config.get('SENDING_NOTIFICATIONS_TIMEOUT_PERIOD')) if updated: current_app.logger.info( "Timeout period reached for {} notifications, status has been updated.".format(updated))