1
2
3
4
5
6
7
8
9
10
11 from collections import defaultdict
12 from itertools import ifilter
13 from zope.component import queryUtility, getUtilitiesFor
14 from zope.interface import implements
15 from .interfaces import IWorkerSelectionAlgorithm
16
18 """
19 Simple selection algorithm that returns workers in the
20 order in which they are given.
21 """
22 implements(IWorkerSelectionAlgorithm)
23
25 return (i for i, worker in enumerate(workers) if not worker.busy)
26
28 """
29 Selection algorithm that returns workers in the
30 order in which they are given, and only returns workers
31 above the reserved threshold.
32 """
33 implements(IWorkerSelectionAlgorithm)
34
39
41 """
42 Selection algorithm that returns workers in the reverse
43 order in which they are given, and only returns workers
44 above the reserved threshold.
45 """
46 implements(IWorkerSelectionAlgorithm)
47
52
53
55 """
56 Singleton worker selector that apportions work to zenhub workers based on the
57 configured utilities per method name.
58 """
59
61 self.options = options
62 self.selectors = {}
63
64 for name, utility in getUtilitiesFor(IWorkerSelectionAlgorithm):
65 self.selectors[name] = utility
66 self.defaultSelector = self.selectors['']
67
69 selector = self.selectors.get(methodName, self.defaultSelector)
70 return selector.getCandidateWorkerIds(workerlist, self.options)
71