-
Notifications
You must be signed in to change notification settings - Fork 1
/
worker.py
executable file
·64 lines (50 loc) · 1.99 KB
/
worker.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
#!/usr/bin/python
# Pull work entries off the queue and execute them
import imp
import os
import socket
import workunit
import utils
if __name__ == '__main__':
cursor = utils.get_cursor()
worker = socket.gethostname()
constraints = utils.get_config().get('constraints', '')
try:
while True:
work = workunit.dequeue_work(cursor, worker, constraints)
print '=========================================================='
work.clear_log(cursor)
# Checkout the patchset
change = utils.get_patchset_details(cursor, work)
conflict = True
rewind = 0
while conflict and rewind < 10:
git_repo, conflict = utils.create_git(change['project'],
change['refurl'],
cursor, work, rewind)
if conflict:
work.log(cursor, 'Git merge failure with HEAD~%d' % rewind)
rewind += 1
if conflict:
work.log(cursor, 'Git merge failure detected')
work.set_conflict(cursor)
continue
work.log(cursor, 'Git checkout created')
# Load plugins
plugins = []
for ent in os.listdir('plugins'):
if ent[0] != '.' and ent.endswith('.py'):
plugin_info = imp.find_module(ent[:-3], ['plugins'])
plugins.append(imp.load_module(ent[:-3], *plugin_info))
handled = False
for plugin in plugins:
handled = plugin.ExecuteWork(cursor, work, git_repo, change)
if handled:
work.set_done(cursor)
break
if not handled:
work.log(cursor,
'No plugin found for work of %s type' % workname)
work.set_missing(cursor)
except workunit.NoWorkFound:
pass