def prepare_app(): """ Prepare a worker application containing the custom washer commands and that can be run without the use of the `buildbot` command script. """ application = service.Application('buildbot-worker') master = (GATEWAY if conf.Washer.FORCE_GATEWAY else conf.Buildbot.BUILDMASTER) worker = Worker(master, conf.Buildbot.BUILDMASTER_PORT, conf.Buildbot.WORKERNAME, conf.Buildbot.WORKERPASS, conf.Buildbot.BASEDIR, conf.Buildbot.KEEPALIVE, umask=None, maxdelay=conf.Buildbot.MAXDELAY, numcpus=None, allow_shutdown=None, maxRetries=None) worker.setServiceParent(application) class InlineApplication(UnixApplicationRunner): def createOrGetApplication(self): nonlocal application return application options = ServerOptions() options["nodaemon"] = not conf.Washer.DAEMON options["logfile"] = conf.Washer.LOG_FILE commands.register() return InlineApplication(options)
def setup_worker(application: service.Application, id: int) -> None: basedir = f"{require_env('BUILDBOT_DIR')}-{id}" os.makedirs(basedir, mode=0o700, exist_ok=True) master_url = require_env("MASTER_URL") hostname = socket.gethostname() workername = f"{hostname}-{id}" with open(require_env("WORKER_PASSWORD_FILE"), "r", encoding="utf-8") as passwd_file: passwd = passwd_file.read().strip("\r\n") keepalive = 600 umask = None maxdelay = 300 numcpus = None allow_shutdown = None s = Worker( None, None, workername, passwd, basedir, keepalive, connection_string=master_url, umask=umask, maxdelay=maxdelay, numcpus=numcpus, allow_shutdown=allow_shutdown, ) s.setServiceParent(application)