-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.py
34 lines (26 loc) · 1.03 KB
/
monitor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from celery import Celery
def monitor(app):
state = app.events.State()
def announce_failed_tasks(event):
state.event(event)
task = state.tasks.get(event['uuid'])
print(f'TASK FAILED: {task.name}[{task.uuid}]')
def announce_succeeded_tasks(event):
state.event(event)
task = state.tasks.get(event['uuid'])
print(f'TASK SUCCEEDED: {task.name}[{task.uuid}]')
def worker_online_handler(event):
state.event(event)
print("New worker gets online")
print(event['hostname'], event['timestamp'], event['freq'], event['sw_ver'])
with app.connection() as connection:
recv = app.events.Receiver(connection, handlers={
'task-failed': announce_failed_tasks,
'task-succeeded': announce_succeeded_tasks,
'worker-online': worker_online_handler,
'*': state.event,
})
recv.capture(limit=None, timeout=None, wakeup=True)
if __name__ == '__main__':
app = Celery('proj')
monitor(app)