mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 14:08:47 -04:00
only check for dvla response files on mon/weds/fri
dvla don't process 2nd class files on tues and thurs
This commit is contained in:
@@ -258,19 +258,27 @@ def raise_alert_if_letter_notifications_still_sending():
|
|||||||
today = datetime.utcnow().date()
|
today = datetime.utcnow().date()
|
||||||
|
|
||||||
# Do nothing on the weekend
|
# Do nothing on the weekend
|
||||||
if today.isoweekday() in [6, 7]:
|
if today.isoweekday() in {6, 7}: # sat, sun
|
||||||
return
|
return
|
||||||
|
|
||||||
if today.isoweekday() in [1, 2]:
|
if today.isoweekday() in {1, 2}: # mon, tues. look for files from before the weekend
|
||||||
offset_days = 4
|
offset_days = 4
|
||||||
else:
|
else:
|
||||||
offset_days = 2
|
offset_days = 2
|
||||||
still_sending = Notification.query.filter(
|
|
||||||
|
q = Notification.query.filter(
|
||||||
Notification.notification_type == LETTER_TYPE,
|
Notification.notification_type == LETTER_TYPE,
|
||||||
Notification.status == NOTIFICATION_SENDING,
|
Notification.status == NOTIFICATION_SENDING,
|
||||||
Notification.key_type == KEY_TYPE_NORMAL,
|
Notification.key_type == KEY_TYPE_NORMAL,
|
||||||
func.date(Notification.sent_at) <= today - timedelta(days=offset_days)
|
func.date(Notification.sent_at) <= today - timedelta(days=offset_days)
|
||||||
).count()
|
)
|
||||||
|
|
||||||
|
if today.isoweekday() in {2, 4}: # on tue, thu, we only care about first class letters
|
||||||
|
q = q.filter(
|
||||||
|
Notification.postage == 'first'
|
||||||
|
)
|
||||||
|
|
||||||
|
still_sending = q.count()
|
||||||
|
|
||||||
if still_sending:
|
if still_sending:
|
||||||
message = "There are {} letters in the 'sending' state from {}".format(
|
message = "There are {} letters in the 'sending' state from {}".format(
|
||||||
|
|||||||
@@ -471,8 +471,8 @@ def test_alert_if_letter_notifications_still_sending_does_nothing_on_the_weekend
|
|||||||
def test_monday_alert_if_letter_notifications_still_sending_reports_thursday_letters(sample_letter_template, mocker):
|
def test_monday_alert_if_letter_notifications_still_sending_reports_thursday_letters(sample_letter_template, mocker):
|
||||||
thursday = datetime(2018, 1, 11, 13, 30)
|
thursday = datetime(2018, 1, 11, 13, 30)
|
||||||
yesterday = datetime(2018, 1, 14, 13, 30)
|
yesterday = datetime(2018, 1, 14, 13, 30)
|
||||||
create_notification(template=sample_letter_template, status='sending', sent_at=thursday)
|
create_notification(template=sample_letter_template, status='sending', sent_at=thursday, postage='second')
|
||||||
create_notification(template=sample_letter_template, status='sending', sent_at=yesterday)
|
create_notification(template=sample_letter_template, status='sending', sent_at=yesterday, postage='second')
|
||||||
|
|
||||||
mock_create_ticket = mocker.patch("app.celery.nightly_tasks.zendesk_client.create_ticket")
|
mock_create_ticket = mocker.patch("app.celery.nightly_tasks.zendesk_client.create_ticket")
|
||||||
|
|
||||||
@@ -489,8 +489,10 @@ def test_monday_alert_if_letter_notifications_still_sending_reports_thursday_let
|
|||||||
def test_tuesday_alert_if_letter_notifications_still_sending_reports_friday_letters(sample_letter_template, mocker):
|
def test_tuesday_alert_if_letter_notifications_still_sending_reports_friday_letters(sample_letter_template, mocker):
|
||||||
friday = datetime(2018, 1, 12, 13, 30)
|
friday = datetime(2018, 1, 12, 13, 30)
|
||||||
yesterday = datetime(2018, 1, 14, 13, 30)
|
yesterday = datetime(2018, 1, 14, 13, 30)
|
||||||
create_notification(template=sample_letter_template, status='sending', sent_at=friday)
|
create_notification(template=sample_letter_template, status='sending', sent_at=friday, postage='first')
|
||||||
create_notification(template=sample_letter_template, status='sending', sent_at=yesterday)
|
create_notification(template=sample_letter_template, status='sending', sent_at=yesterday, postage='first')
|
||||||
|
# doesn't get reported because it's second class, and it's tuesday today
|
||||||
|
create_notification(template=sample_letter_template, status='sending', sent_at=friday, postage='second')
|
||||||
|
|
||||||
mock_create_ticket = mocker.patch("app.celery.nightly_tasks.zendesk_client.create_ticket")
|
mock_create_ticket = mocker.patch("app.celery.nightly_tasks.zendesk_client.create_ticket")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user