mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
Disable Deskpro letters still sending alert in preview and staging
Since preview and staging environments don't have a full DVLA integration they're likely to contain letter notifications in a 'sending' state. To avoid spamming Deskpro we skip the check unless we're in a production or test environment.
This commit is contained in:
@@ -337,6 +337,7 @@ def delete_dvla_response_files_older_than_seven_days():
|
|||||||
@notify_celery.task(name="raise-alert-if-letter-notifications-still-sending")
|
@notify_celery.task(name="raise-alert-if-letter-notifications-still-sending")
|
||||||
@statsd(namespace="tasks")
|
@statsd(namespace="tasks")
|
||||||
def raise_alert_if_letter_notifications_still_sending():
|
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
|
||||||
@@ -356,15 +357,21 @@ def raise_alert_if_letter_notifications_still_sending():
|
|||||||
).count()
|
).count()
|
||||||
|
|
||||||
if still_sending:
|
if still_sending:
|
||||||
deskpro_client.create_ticket(
|
message = "There are {} letters in the 'sending' state from {}".format(
|
||||||
subject="Letters still sending",
|
still_sending,
|
||||||
message="There are {} letters in the 'sending' state from {}".format(
|
(today - timedelta(days=offset_days)).strftime('%A %d %B')
|
||||||
still_sending,
|
|
||||||
(today - timedelta(days=offset_days)).strftime('%A %d %B')
|
|
||||||
),
|
|
||||||
ticket_type="alert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Only send alerts in production
|
||||||
|
if current_app.config['NOTIFY_ENVIRONMENT'] in ['production', 'test']:
|
||||||
|
deskpro_client.create_ticket(
|
||||||
|
subject="[{}] Letters still sending".format(current_app.config['NOTIFY_ENVIRONMENT']),
|
||||||
|
message=message,
|
||||||
|
ticket_type="alert"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
current_app.logger.info(message)
|
||||||
|
|
||||||
|
|
||||||
@notify_celery.task(name="populate_monthly_billing")
|
@notify_celery.task(name="populate_monthly_billing")
|
||||||
@statsd(namespace="tasks")
|
@statsd(namespace="tasks")
|
||||||
|
|||||||
@@ -642,7 +642,7 @@ def test_alert_if_letter_notifications_still_sending(sample_letter_template, moc
|
|||||||
raise_alert_if_letter_notifications_still_sending()
|
raise_alert_if_letter_notifications_still_sending()
|
||||||
|
|
||||||
mock_celery.assert_called_once_with(
|
mock_celery.assert_called_once_with(
|
||||||
subject="Letters still sending",
|
subject="[test] Letters still sending",
|
||||||
message="There are 1 letters in the 'sending' state from Tuesday 16 January",
|
message="There are 1 letters in the 'sending' state from Tuesday 16 January",
|
||||||
ticket_type='alert'
|
ticket_type='alert'
|
||||||
)
|
)
|
||||||
@@ -660,7 +660,7 @@ def test_alert_if_letter_notifications_still_sending_only_alerts_sending(sample_
|
|||||||
raise_alert_if_letter_notifications_still_sending()
|
raise_alert_if_letter_notifications_still_sending()
|
||||||
|
|
||||||
mock_celery.assert_called_once_with(
|
mock_celery.assert_called_once_with(
|
||||||
subject="Letters still sending",
|
subject="[test] Letters still sending",
|
||||||
message="There are 1 letters in the 'sending' state from Tuesday 16 January",
|
message="There are 1 letters in the 'sending' state from Tuesday 16 January",
|
||||||
ticket_type='alert'
|
ticket_type='alert'
|
||||||
)
|
)
|
||||||
@@ -703,7 +703,7 @@ def test_monday_alert_if_letter_notifications_still_sending_reports_friday_lette
|
|||||||
raise_alert_if_letter_notifications_still_sending()
|
raise_alert_if_letter_notifications_still_sending()
|
||||||
|
|
||||||
mock_celery.assert_called_once_with(
|
mock_celery.assert_called_once_with(
|
||||||
subject="Letters still sending",
|
subject="[test] Letters still sending",
|
||||||
message="There are 2 letters in the 'sending' state from Friday 12 January",
|
message="There are 2 letters in the 'sending' state from Friday 12 January",
|
||||||
ticket_type='alert'
|
ticket_type='alert'
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user