Package buildbot :: Package changes :: Module base
[frames] | no frames]

Source Code for Module buildbot.changes.base

 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  from twisted.application import service 
18  from twisted.internet import defer, task, reactor 
19  from twisted.python import log 
20   
21  from buildbot.interfaces import IChangeSource 
22  from buildbot import util 
23   
24 -class ChangeSource(service.Service, util.ComparableMixin):
25 implements(IChangeSource) 26 27 master = None 28 "if C{self.running} is true, then C{cs.master} points to the buildmaster." 29
30 - def describe(self):
31 pass
32
33 -class PollingChangeSource(ChangeSource):
34 """ 35 Utility subclass for ChangeSources that use some kind of periodic polling 36 operation. Subclasses should define C{poll} and set C{self.pollInterval}. 37 The rest is taken care of. 38 """ 39 40 pollInterval = 60 41 "time (in seconds) between calls to C{poll}" 42 43 _loop = None 44
45 - def poll(self):
46 """ 47 Perform the polling operation, and return a deferred that will fire 48 when the operation is complete. Failures will be logged, but the 49 method will be called again after C{pollInterval} seconds. 50 """
51
52 - def startService(self):
53 ChangeSource.startService(self) 54 def do_poll(): 55 d = defer.maybeDeferred(self.poll) 56 d.addErrback(log.err, 'while polling for changes') 57 return d
58 59 # delay starting the loop until the reactor is running, and do not 60 # run it immediately - if services are still starting up, they may 61 # miss an initial flood of changes 62 def start_loop(): 63 self._loop = task.LoopingCall(do_poll) 64 self._loop.start(self.pollInterval, now=False)
65 reactor.callWhenRunning(start_loop) 66
67 - def stopService(self):
68 if self._loop and self._loop.running: 69 self._loop.stop() 70 return ChangeSource.stopService(self)
71