File tree Expand file tree Collapse file tree
lung_cancer_screening/questions/management/commands Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,13 +9,33 @@ class Command(BaseCommand):
99 help = "Counts the number of submitted requests."
1010
1111 def handle (self , * args , ** options ):
12- logger .info ("Command: SubmittedCount." )
12+
13+ logger .info ("Command: Request Summary." )
1314 try :
1415 rs = RequestSummary ()
1516 summary = rs .get_summary ()
1617
1718 self .stdout .write (str (summary ))
1819
20+ slack_webhook_url = os .environ .get ("SLACK_WEBHOOK_URL" )
21+
22+ if not slack_webhook_url :
23+ logger .warning ("SLACK_WEBHOOK_URL is not set; skipping Slack notification." )
24+ return
25+
26+ payload = {
27+ "text" : f"*Request summary*\n ```{ json .dumps (summary , indent = 2 , default = str )} ```"
28+ }
29+
30+ response = requests .post (
31+ slack_webhook_url ,
32+ json = payload ,
33+ timeout = 10 ,
34+ )
35+ response .raise_for_status ()
36+
37+ logger .info ("Request summary sent to Slack." )
38+
1939 except Exception as e :
2040 logger .error (e , exc_info = True )
2141 raise CommandError (e )
You can’t perform that action at this time.
0 commit comments