| Total Complexity | 4 |
| Total Lines | 25 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | '''what to do when an alert is triggered''' |
||
| 2 | from helpers.queuehelper import QueueName |
||
| 3 | from backend.fcmapp import Component |
||
| 4 | |||
| 5 | ALERT = Component('alert') |
||
| 6 | |||
| 7 | def when_alert(channel, method, properties, body): |
||
| 8 | '''when alert is fired''' |
||
| 9 | try: |
||
| 10 | print("[{0}] Received request to send telegram".format(ALERT.app.now())) |
||
| 11 | doalert(body.decode()) |
||
| 12 | except Exception as ex: |
||
| 13 | ALERT.app.logexception(ex) |
||
| 14 | |||
| 15 | def doalert(alertmsg): |
||
| 16 | '''send the alert''' |
||
| 17 | ALERT.app.telegram.sendmessage(alertmsg) |
||
| 18 | print("Sent telegram {0}".format(alertmsg)) |
||
| 19 | |||
| 20 | def main(): |
||
| 21 | ALERT.listeningqueue = ALERT.app.listen_to_broadcast(QueueName.Q_ALERT, when_alert) |
||
| 22 | |||
| 23 | if __name__ == "__main__": |
||
| 24 | main() |
||
| 25 |