/ monkeypatch.py
monkeypatch.py
1 from twisted.python import log 2 from twisted.internet import reactor 3 4 5 def botmaster_maybeStartBuildsForSlave(self, slave_name): 6 """ 7 We delay this for 10 seconds, so that if multiple slaves start at the same 8 time, builds will be distributed between them. 9 """ 10 def do_start(): 11 log.msg(format="Really starting builds on %(slave_name)s", 12 slave_name=slave_name) 13 builders = self.getBuildersForSlave(slave_name) 14 self.brd.maybeStartBuildsOn([b.name for b in builders]) 15 log.msg(format="Waiting to start builds on %(slave_name)s", 16 slave_name=slave_name) 17 reactor.callLater(10, do_start) 18 19 20 from buildbot.process.slavebuilder import AbstractSlaveBuilder 21 22 23 def slavebuilder_buildStarted(self): 24 AbstractSlaveBuilder.buildStarted(self) 25 if self.slave and hasattr(self.slave, 'buildStarted'): 26 self.slave.buildStarted(self) 27 28 29 from buildbot.process.buildrequestdistributor import BasicBuildChooser 30 31 32 class NoFallBackBuildChooser(BasicBuildChooser): 33 """ 34 BuildChooser that doesn't fall back to rejected slaves. 35 In particular, builds with locks won't be assigned before a lock is ready. 36 """ 37 38 def __init__(self, bldr, master): 39 BasicBuildChooser.__init__(self, bldr, master) 40 self.rejectedSlaves = None 41 42 43 def apply_patches(): 44 log.msg("Apply flocker_bb.monkeypatch.") 45 from buildbot.process.botmaster import BotMaster 46 BotMaster.maybeStartBuildsForSlave = botmaster_maybeStartBuildsForSlave 47 from buildbot.process.slavebuilder import SlaveBuilder 48 SlaveBuilder.buildStarted = slavebuilder_buildStarted 49 from buildbot.steps.master import MasterShellCommand 50 MasterShellCommand.renderables += ['path'] 51 from buildbot.process.buildrequestdistributor import ( 52 BuildRequestDistributor) 53 BuildRequestDistributor.BuildChooser = NoFallBackBuildChooser