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:
Alexey Bezhan
2018-08-31 16:49:06 +01:00
parent 18ab7f3337
commit 3787e2954b
6 changed files with 82 additions and 2 deletions

View File

@@ -1309,7 +1309,7 @@ class Notification(db.Model):
if self.status in [NOTIFICATION_CREATED, NOTIFICATION_SENDING]:
return NOTIFICATION_STATUS_LETTER_ACCEPTED
elif self.status == NOTIFICATION_DELIVERED:
elif self.status in [NOTIFICATION_DELIVERED, NOTIFICATION_RETURNED_LETTER]:
return NOTIFICATION_STATUS_LETTER_RECEIVED
else:
# Currently can only be technical-failure