This repository has been archived by the owner on May 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
listener.py
executable file
·65 lines (55 loc) · 2.05 KB
/
listener.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
import sys
import json
import pprint
try:
import zmq
except ImportError:
print >> sys.stderr, "Please install python-zmq rpm package"
sys.exit(-1)
try:
from tasks import process
except ImportError:
print >> sys.stderr, "Please install celery from PyPI and koji rpm package"
sys.exit(-1)
def listen_and_print():
# You can listen to stg at "tcp://stg.fedoraproject.org:9940"
endpoint = "tcp://hub.fedoraproject.org:9940"
topic1 = 'org.fedoraproject.prod.buildsys.build.state.change'
topic2 = 'org.fedoraproject.prod.bodhi.update.request.stable'
topic3 = 'org.fedoraproject.prod.git.receive'
topic4 = 'org.fedoraproject.prod.git.lookaside.new'
topic5 = 'org.fedoraproject.prod.bodhi.update.request.testing'
topic6 = 'org.fedoraproject.prod.bodhi.update.request.stable'
ctx = zmq.Context()
s = ctx.socket(zmq.SUB)
s.connect(endpoint)
# s.setsockopt(zmq.SUBSCRIBE, topic6)
# s.setsockopt(zmq.SUBSCRIBE, topic5)
# s.setsockopt(zmq.SUBSCRIBE, topic4)
s.setsockopt(zmq.SUBSCRIBE, topic3)
# s.setsockopt(zmq.SUBSCRIBE, topic2)
s.setsockopt(zmq.SUBSCRIBE, topic1)
poller = zmq.Poller()
poller.register(s, zmq.POLLIN)
while True:
evts = poller.poll() # This blocks until a message arrives
topic, msg = s.recv_multipart()
print topic
if topic == topic1:
data = json.loads(msg)
if "msg" in data:
if "build_id" in data["msg"]:
state = data["msg"]["new"]
bid = data["msg"]["build_id"]
name = data["msg"]["name"]
if state != 1:
print ">>> skipping", bid, "with state", state, "and name", name
continue
# print data
print ">>> adding", bid, "with state", state, "and name", name
process.delay(bid)
elif topic == topic5 or topic == topic6:
print msg
if __name__ == "__main__":
listen_and_print()