mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-14 17:22:17 -05:00
Add a task to process returned letter lists
Adds an API endpoint `/letters/returned` that accepts a list of notification references and creates a task to update their status. Adds a new task that uses the list of references to update the status of notifications to 'returned-letter'. The update is currently done using a single query and logs the number of changed records (including notification history records). This could potentially be done within the `/letters/returned` endpoint, but creating a job right away allows us to extend this more easily in the future (e.g. logging missing notifications or adding callbacks). The job is using the database tasks queue.
This commit is contained in:
@@ -64,6 +64,7 @@ from app.models import (
|
||||
NOTIFICATION_SENDING,
|
||||
NOTIFICATION_TEMPORARY_FAILURE,
|
||||
NOTIFICATION_TECHNICAL_FAILURE,
|
||||
NOTIFICATION_RETURNED_LETTER,
|
||||
SMS_TYPE,
|
||||
DailySortedLetter,
|
||||
)
|
||||
@@ -591,3 +592,18 @@ def process_incomplete_job(job_id):
|
||||
process_row(row, template, job, job.service)
|
||||
|
||||
job_complete(job, resumed=True)
|
||||
|
||||
|
||||
@notify_celery.task(name='process-returned-letters-list')
|
||||
@statsd(namespace="tasks")
|
||||
def process_returned_letters_list(notification_references):
|
||||
updated, updated_history = dao_update_notifications_by_reference(
|
||||
notification_references,
|
||||
{"status": NOTIFICATION_RETURNED_LETTER}
|
||||
)
|
||||
|
||||
current_app.logger.info(
|
||||
"Updated {} letter notifications ({} history notifications, from {} references) to returned-letter".format(
|
||||
updated, updated_history, len(notification_references)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user