-
Notifications
You must be signed in to change notification settings - Fork 9
/
cfbot.py
executable file
·63 lines (51 loc) · 1.7 KB
/
cfbot.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
#!/usr/bin/env python3
import cfbot_cirrus
import cfbot_commitfest
import cfbot_commitfest_rpc
import cfbot_config
import cfbot_patch
import cfbot_util
import cfbot_web
import errno
import fcntl
import logging
def try_lock():
"""Make sure that only one copy runs."""
fd = open(cfbot_config.LOCK_FILE, "w")
try:
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
return fd
except IOError as e:
if e.errno != errno.EAGAIN:
raise
else:
return None
def run():
with cfbot_util.db() as conn:
# get the current Commitfest ID
commitfest_id = cfbot_commitfest_rpc.get_current_commitfest_id()
# pull in any build results that we are waiting for
# XXX would need to aggregate the 'keep_polling' flag if we went
# back to supporting multiple providers, or do something smarter,
# but considering the plan to double-down on cirrus and switch to
# webhooks, not bothering for now
cfbot_cirrus.pull_build_results(conn)
# exchange data with the Commitfest app
logging.info("pulling submissions for current commitfest")
cfbot_commitfest.pull_submissions(conn, commitfest_id)
logging.info("pulling submissions for next commitfest")
cfbot_commitfest.pull_submissions(conn, commitfest_id + 1)
logging.info("pulling modified threads")
cfbot_commitfest.pull_modified_threads(conn)
# build one patch, if it is time for that
cfbot_patch.maybe_process_one(conn, commitfest_id)
# rebuild a new set of web pages
cfbot_web.rebuild(conn, commitfest_id)
# garbage collect old build results
cfbot_util.gc(conn)
if __name__ == "__main__":
# don't run if we're already running
lock_fd = try_lock()
if lock_fd:
run()
lock_fd.close()