Total Complexity | 9 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | '''David Foderick, Skylake Software Inc. |
||
2 | ''' |
||
3 | from helpers.queuehelper import QueueName, QueueEntries |
||
4 | from backend.fcmapp import Component |
||
5 | |||
6 | MONITOR = Component('monitor') |
||
7 | |||
8 | def when_monitor(channel, method, properties, body): |
||
9 | '''when its time to monitor all the machines on schedule''' |
||
10 | try: |
||
11 | print("[{0}] Received monitor command".format(MONITOR.app.now())) |
||
12 | entries = domonitor() |
||
13 | MONITOR.app.enqueue(entries) |
||
14 | except Exception as ex: |
||
15 | MONITOR.app.logexception(ex) |
||
16 | |||
17 | def domonitor(): |
||
18 | '''queue workers to run the individual miner monitoring''' |
||
19 | entries = QueueEntries() |
||
20 | try: |
||
21 | miners = MONITOR.app.allminers() |
||
22 | print("{0} miners configured".format(len(miners))) |
||
23 | |||
24 | for miner in miners: |
||
25 | if not miner.is_manually_disabled(): |
||
26 | entries.add(QueueName.Q_MONITORMINER, MONITOR.app.messageencode(miner)) |
||
27 | print("waiting for next monitor event") |
||
28 | except Exception as theex: |
||
29 | MONITOR.app.logexception(theex) |
||
30 | return entries |
||
31 | |||
32 | def main(): |
||
33 | if MONITOR.app.isrunnow or MONITOR.app.isdebug: |
||
34 | domonitor() |
||
35 | MONITOR.app.shutdown() |
||
36 | else: |
||
37 | MONITOR.listeningqueue = MONITOR.app.subscribe(QueueName.Q_MONITOR, when_monitor) |
||
38 | MONITOR.app.listen(MONITOR.listeningqueue) |
||
39 | |||
40 | if __name__ == "__main__": |
||
41 | main() |
||
42 |