mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-06 21:58:26 -04:00
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:
@@ -48,6 +48,12 @@ class Job(JSONModel):
|
||||
def scheduled_for(self):
|
||||
return self._dict.get('scheduled_for')
|
||||
|
||||
@property
|
||||
def processing_started(self):
|
||||
if not self._dict.get('processing_started'):
|
||||
return None
|
||||
return datetime.strptime(self._dict['processing_started'][:-6], '%Y-%m-%dT%H:%M:%S')
|
||||
|
||||
def _aggregate_statistics(self, *statuses):
|
||||
return sum(
|
||||
outcome['count'] for outcome in self._dict['statistics']
|
||||
@@ -95,6 +101,17 @@ class Job(JSONModel):
|
||||
def finished_processing(self):
|
||||
return self.notification_count == self.notifications_sent
|
||||
|
||||
@property
|
||||
def recently_created(self):
|
||||
if not self.processing_started:
|
||||
# Assume that if processing hasn’t started yet then the job
|
||||
# must have been created recently enough to not have any
|
||||
# notifications yet
|
||||
return True
|
||||
return (
|
||||
datetime.utcnow() - self.processing_started
|
||||
).days < 1
|
||||
|
||||
@property
|
||||
def template_id(self):
|
||||
return self._dict['template']
|
||||
|
||||
Reference in New Issue
Block a user