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 
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 - def describe(self):
28 return "no description"
29
30 -class PollingChangeSource(ChangeSource):
31 """ 32 Utility subclass for ChangeSources that use some kind of periodic polling 33 operation. Subclasses should define C{poll} and set C{self.pollInterval}. 34 The rest is taken care of. 35 """ 36 37 pollInterval = 60 38 "time (in seconds) between calls to C{poll}" 39 40 _loop = None 41 volatile = ['_loop'] # prevents Twisted from pickling this value 42
43 - def poll(self):
44 """ 45 Perform the polling operation, and return a deferred that will fire 46 when the operation is complete. Failures will be logged, but the 47 method will be called again after C{pollInterval} seconds. 48 """
49
50 - def startService(self):
51 ChangeSource.startService(self) 52 def do_poll(): 53 d = defer.maybeDeferred(self.poll) 54 d.addErrback(log.err) 55 return d
56 self._loop = task.LoopingCall(do_poll) 57 self._loop.start(self.pollInterval)
58
59 - def stopService(self):
60 self._loop.stop() 61 return ChangeSource.stopService(self)
62