Package buildbot :: Package schedulers :: Module triggerable
[frames] | no frames]

Source Code for Module buildbot.schedulers.triggerable

 1  # This file is part of Buildbot.  Buildbot is free software: you can 
 2  # redistribute it and/or modify it under the terms of the GNU General Public 
 3  # License as published by the Free Software Foundation, version 2. 
 4  # 
 5  # This program is distributed in the hope that it will be useful, but WITHOUT 
 6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
 8  # details. 
 9  # 
10  # You should have received a copy of the GNU General Public License along with 
11  # this program; if not, write to the Free Software Foundation, Inc., 51 
12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
13  # 
14  # Copyright Buildbot Team Members 
15   
16  from twisted.python import failure 
17  from twisted.internet import defer 
18  from buildbot.schedulers import base 
19  from buildbot.process.properties import Properties 
20   
21 -class Triggerable(base.BaseScheduler):
22 23 compare_attrs = base.BaseScheduler.compare_attrs 24
25 - def __init__(self, name, builderNames, properties={}):
26 base.BaseScheduler.__init__(self, name, builderNames, properties) 27 self._waiters = {} 28 self._bsc_subscription = None 29 self.reason = "Triggerable(%s)" % name
30
31 - def trigger(self, ss_setid, set_props=None):
32 """Trigger this scheduler with the given sourcestampset ID. Returns a 33 deferred that will fire when the buildset is finished.""" 34 # properties for this buildset are composed of our own properties, 35 # potentially overridden by anything from the triggering build 36 props = Properties() 37 props.updateFromProperties(self.properties) 38 if set_props: 39 props.updateFromProperties(set_props) 40 41 # note that this does not use the buildset subscriptions mechanism, as 42 # the duration of interest to the caller is bounded by the lifetime of 43 # this process. 44 if ss_setid: 45 d = self.addBuildsetForSourceStamp(reason=self.reason, setid=ss_setid, 46 properties=props) 47 else: 48 d = self.addBuildsetForLatest(reason=self.reason, properties=props) 49 def setup_waiter((bsid,brids)): 50 d = defer.Deferred() 51 self._waiters[bsid] = (d, brids) 52 self._updateWaiters() 53 return d
54 d.addCallback(setup_waiter) 55 return d
56
57 - def stopService(self):
58 # cancel any outstanding subscription 59 if self._bsc_subscription: 60 self._bsc_subscription.unsubscribe() 61 self._bsc_subscription = None 62 63 # and errback any outstanding deferreds 64 if self._waiters: 65 msg = 'Triggerable scheduler stopped before build was complete' 66 for d, brids in self._waiters.values(): 67 d.errback(failure.Failure(RuntimeError(msg))) 68 self._waiters = {} 69 70 return base.BaseScheduler.stopService(self)
71
72 - def _updateWaiters(self):
73 if self._waiters and not self._bsc_subscription: 74 self._bsc_subscription = \ 75 self.master.subscribeToBuildsetCompletions( 76 self._buildsetComplete) 77 elif not self._waiters and self._bsc_subscription: 78 self._bsc_subscription.unsubscribe() 79 self._bsc_subscription = None
80
81 - def _buildsetComplete(self, bsid, result):
82 if bsid not in self._waiters: 83 return 84 85 # pop this bsid from the waiters list, and potentially unsubscribe 86 # from completion notifications 87 d, brids = self._waiters.pop(bsid) 88 self._updateWaiters() 89 90 # fire the callback to indicate that the triggered build is complete 91 d.callback((result, brids))
92