1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from twisted.internet import defer
17 from twisted.application import service
18 from twisted.python import log, reflect
19 from buildbot.process import metrics
20 from buildbot import config, util
21
22 -class SchedulerManager(config.ReconfigurableServiceMixin,
23 service.MultiService):
28
29 @defer.inlineCallbacks
31 timer = metrics.Timer("SchedulerManager.reconfigService")
32 timer.start()
33
34 old_by_name = dict((sch.name, sch) for sch in self)
35 old_set = set(old_by_name.iterkeys())
36 new_by_name = new_config.schedulers
37 new_set = set(new_by_name.iterkeys())
38
39 removed_names, added_names = util.diffSets(old_set, new_set)
40
41
42
43
44
45
46 for n in old_set & new_set:
47 old = old_by_name[n]
48 new = new_by_name[n]
49
50 if reflect.qual(old.__class__) != reflect.qual(new.__class__):
51 removed_names.add(n)
52 added_names.add(n)
53
54
55 elif not hasattr(old, 'reconfigService'):
56 if old != new:
57 removed_names.add(n)
58 added_names.add(n)
59
60
61
62 for sch_name in removed_names:
63 log.msg("removing scheduler '%s'" % (sch_name,))
64 sch = old_by_name[sch_name]
65 yield defer.maybeDeferred(lambda :
66 sch.disownServiceParent())
67 sch.master = None
68
69
70
71 for sch_name in added_names:
72 log.msg("adding scheduler '%s'" % (sch_name,))
73 sch = new_by_name[sch_name]
74
75
76 class_name = '%s.%s' % (sch.__class__.__module__,
77 sch.__class__.__name__)
78 objectid = yield self.master.db.state.getObjectId(
79 sch.name, class_name)
80
81
82 sch.objectid = objectid
83 sch.master = self.master
84
85
86 sch.setServiceParent(self)
87
88 metrics.MetricCountEvent.log("num_schedulers", len(list(self)),
89 absolute=True)
90
91
92 yield config.ReconfigurableServiceMixin.reconfigService(self,
93 new_config)
94
95 timer.stop()
96