44from django .core .management .base import BaseCommand
55from django .utils import timezone
66from notifications .models import SurgeAlert , SurgeAlertStatus
7+ from api .models import CronJob , CronJobStatus
78
89logger = logging .getLogger (__name__ )
910
1011class 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 \n Exception:\n { str (e )} ' ,
42+ 'status' : CronJobStatus .ERRONEOUS ,
43+ })
44+ logger .error ('Error while updating surge alerts status' , exc_info = True )
0 commit comments