Buildbot slaves priority

一笑奈何 提交于 2019-12-12 01:32:14

问题


Problem

I have set up a latent slave in buildbot to help avoid congestion. I've set up my builds to run either in permanent slave or latent one. The idea is the latent slave is waken up only when needed but the result is that buildbot randomly selectes one slave or the other so sometimes I have to wait for the latent slave to wake even if the permanent one is idle.

Is there a way to prioritize buildbot slaves?

Attempted solutions

1. Custom nextSlave

Following @david-dean suggestion, I've created a nextSlave function as follows (updated to working version):

from twisted.python import log
import traceback

def slave_selector(builder, builders):
    try:
        host = None
        support = None
        for builder in builders:
            if builder.slave.slavename == 'host-slave':
                host = builder
            elif builder.slave.slavename == 'support-slave':
                support = builder

        if host and support and len(support.slave.slave_status.runningBuilds) < len(host.slave.slave_status.runningBuilds):
            log.msg('host-slave has many running builds, launching build in support-slave')
            return support
        if not support:
            log.msg('no support slave found, launching build in host-slave')
        elif not host:
            log.msg('no host slave found, launching build in support-slave')
            return support
        else:
            log.msg('launching build in host-slave')
        return host
    except Exception as e:
        log.err(str(e))
        log.err(traceback.format_exc())
        log.msg('Selecting random slave')
        return random.choice(buildslaves)

And then passed it to BuilderConfig. The result is that I get this in twistd.log:

2014-04-28 11:01:45+0200 [-] added buildset 4329 to database

But the build never starts, in the web UI it always appear as Pending and none of the logs I've put appear in twistd.log

2. Trying to mimic default behavior

I've having a look to buildbot code, to see how it is done by default. in file ./master/buildbot/process/buildrequestdistributor.py, class BasicBuildChooser you have:

self.nextSlave = self.bldr.config.nextSlave
if not self.nextSlave:
    self.nextSlave = lambda _,slaves: random.choice(slaves) if slaves else None

So I've set exactly that lambda function in my BuilderConfig and I'm getting exactly the same build not starting result.


回答1:


You can set up a nextSlave function to assign slaves to a builder in a custom manner see: http://docs.buildbot.net/current/manual/cfg-builders.html#builder-configuration



来源:https://stackoverflow.com/questions/23288323/buildbot-slaves-priority

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!