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 zope.interface import implements 
17   
18  from twisted.python import failure 
19  from twisted.internet import defer 
20  from buildbot.interfaces import ITriggerableScheduler 
21  from buildbot.schedulers import base 
22  from buildbot.process.properties import Properties 
23   
24 -class Triggerable(base.BaseScheduler):
25 implements(ITriggerableScheduler) 26 27 compare_attrs = base.BaseScheduler.compare_attrs 28
29 - def __init__(self, name, builderNames, properties={}, **kwargs):
30 base.BaseScheduler.__init__(self, name, builderNames, properties, 31 **kwargs) 32 self._waiters = {} 33 self._bsc_subscription = None 34 self.reason = "Triggerable(%s)" % name
35
36 - def trigger(self, sourcestamps = None, set_props=None):
37 """Trigger this scheduler with the optional given list of sourcestamps 38 Returns a deferred that will fire when the buildset is finished.""" 39 # properties for this buildset are composed of our own properties, 40 # potentially overridden by anything from the triggering build 41 props = Properties() 42 props.updateFromProperties(self.properties) 43 if set_props: 44 props.updateFromProperties(set_props) 45 46 # note that this does not use the buildset subscriptions mechanism, as 47 # the duration of interest to the caller is bounded by the lifetime of 48 # this process. 49 d = self.addBuildsetForSourceStampSetDetails(self.reason, 50 sourcestamps, props) 51 def setup_waiter((bsid,brids)): 52 d = defer.Deferred() 53 self._waiters[bsid] = (d, brids) 54 self._updateWaiters() 55 return d
56 d.addCallback(setup_waiter) 57 return d
58
59 - def stopService(self):
60 # cancel any outstanding subscription 61 if self._bsc_subscription: 62 self._bsc_subscription.unsubscribe() 63 self._bsc_subscription = None 64 65 # and errback any outstanding deferreds 66 if self._waiters: 67 msg = 'Triggerable scheduler stopped before build was complete' 68 for d, brids in self._waiters.values(): 69 d.errback(failure.Failure(RuntimeError(msg))) 70 self._waiters = {} 71 72 return base.BaseScheduler.stopService(self)
73 74
75 - def _updateWaiters(self):
76 if self._waiters and not self._bsc_subscription: 77 self._bsc_subscription = \ 78 self.master.subscribeToBuildsetCompletions( 79 self._buildsetComplete) 80 elif not self._waiters and self._bsc_subscription: 81 self._bsc_subscription.unsubscribe() 82 self._bsc_subscription = None
83
84 - def _buildsetComplete(self, bsid, result):
85 if bsid not in self._waiters: 86 return 87 88 # pop this bsid from the waiters list, and potentially unsubscribe 89 # from completion notifications 90 d, brids = self._waiters.pop(bsid) 91 self._updateWaiters() 92 93 # fire the callback to indicate that the triggered build is complete 94 d.callback((result, brids))
95