Skip to content

Commit a770669

Browse files
committed
Add logging info in surge alert script
1 parent 0214b5e commit a770669

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

notifications/management/commands/update_surge_alert_status.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44
from django.core.management.base import BaseCommand
55
from django.utils import timezone
66
from notifications.models import SurgeAlert, SurgeAlertStatus
7+
from api.models import CronJob, CronJobStatus
78

89
logger = logging.getLogger(__name__)
910

1011
class Command(BaseCommand):
1112
'''
12-
Updating the Alert Status according:
13+
Updating the Surge Alert Status according:
1314
If the alert status is marked as stood_down, then the status is Stood Down.
1415
If the closing timestamp (closes) is earlier than the current date, the status is displayed as Closed. Otherwise, it is displayed as Open.
1516
'''
16-
help = 'Update alert status'
17+
help = 'Update surge alert status'
1718

1819
def handle(self, *args, **options):
1920
now = timezone.now()
2021
try:
22+
logger.info('Updating Surge alerts status')
2123
SurgeAlert.objects.update(
2224
status=models.Case(
2325
models.When(is_stood_down=True, then=models.Value(SurgeAlertStatus.STOOD_DOWN)),
@@ -27,5 +29,16 @@ def handle(self, *args, **options):
2729
output_field=models.IntegerField()
2830
)
2931
)
32+
CronJob.sync_cron({
33+
'name': 'update_surge_alert_status',
34+
'message': f'Updated Surge alerts status',
35+
'status': CronJobStatus.SUCCESSFUL,
36+
})
37+
logger.info('Updated Surge alerts status')
3038
except Exception as e:
31-
logger.error('Error while updating alerts status', exc_info=True)
39+
CronJob.sync_cron({
40+
'name': 'update_surge_alert_status',
41+
'message': f'Error while updating Surge alerts status\n\nException:\n{str(e)}',
42+
'status': CronJobStatus.ERRONEOUS,
43+
})
44+
logger.error('Error while updating surge alerts status', exc_info=True)

0 commit comments

Comments
 (0)