Use time to determine why notifications don’t exist

Notifications won’t exist for a job if:
- it’s just started
- it started a long time ago (older than the retention period)

We have a bug where:
1. Job starts processing, puts notifications on queue
2. Job finishes processing, sets status to `finished`
3. First notification gets picked up off the queue and put in the
   database

In between 2. and 3. it’s possible for a job to be finished, but also to
have no notifications. We’re saying this is because the notifications
have been deleted, whereas really it’s because they haven’t been created
yet.

This commit fixes that bug by introducing the concept of recency for
jobs.

‘Recent’ is defined as 1 day, which is:
- a lot longer than it takes to create any notifications
- a bit shorter than anyone’s retention time

N.B. `processing_started` is defined here:
879ba1d5f0/app/models.py (L1194)

It can be `None` for scheduled jobs that haven’t started yet.
This commit is contained in:
Chris Hill-Scott
2020-01-16 16:58:26 +00:00
parent 462a3b56a0
commit 87b2686875
4 changed files with 60 additions and 8 deletions

View File

@@ -361,7 +361,8 @@ def job_json(
notifications_sent=1,
notifications_requested=1,
job_status='finished',
scheduled_for=''
scheduled_for='',
processing_started=None,
):
if job_id is None:
job_id = str(generate_uuid())
@@ -391,8 +392,11 @@ def job_json(
created_by['name'],
created_by['email_address'],
),
'scheduled_for': scheduled_for
}
if scheduled_for:
data.update(scheduled_for=scheduled_for)
if processing_started:
data.update(processing_started=processing_started)
return data