-
Notifications
You must be signed in to change notification settings - Fork 11
/
triage_ansible_mp.py
executable file
·96 lines (71 loc) · 2.5 KB
/
triage_ansible_mp.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import datetime
import json
import logging
import os
import sys
import tempfile
import time
from itertools import zip_longest
from multiprocessing import Process
from logzero import logger
from ansibullbot.triagers.ansible import AnsibleTriage
def run_triage_worker(numbers):
thispid = os.getpid()
logger.info('%s started with %s numbers' % (str(thispid), len(numbers)))
tfh,tfn = tempfile.mkstemp(suffix='.json')
#logger.info('%s %s' % (thispid, tfh))
logger.info('%s %s' % (thispid, tfn))
with open(tfn, 'w') as f:
f.write(json.dumps(numbers))
args = sys.argv[1:]
args.append('--id=%s' % tfn)
logger.info(args)
triager = AnsibleTriage(args=args, update_checkouts=False)
triager.run()
os.remove(tfn)
return (tfn)
def grouper(n, iterable, padvalue=None):
return zip_longest(*[iter(iterable)]*n, fillvalue=padvalue)
def main():
workercount = 8
ts1 = datetime.datetime.now()
# Run the triager ...
#AnsibleTriage(args=sys.argv[1:]).start()
# init just creates all the tools ...
parent = AnsibleTriage(args=sys.argv[1:])
# collect_repos() gets all the issues to be triaged ...
parent.collect_repos()
# get the issue numbers
numbers = parent.repos['ansible/ansible']['issues'].numbers[:]
# make a range of numbers for each worker
chunks = grouper(int(len(numbers) / (workercount - 1)), numbers)
chunks = list(chunks)
# start each worker with it's numbers
pids = []
for chunk in chunks:
p = Process(target=run_triage_worker, args=(chunk,))
pids.append(p)
[x.start() for x in pids]
[x.join() for x in pids]
ts2 = datetime.datetime.now()
td = (ts2 - ts1).total_seconds()
logger.info('COMPLETED MP TRIAGE IN %s SECONDS' % td)
if __name__ == "__main__":
main()