Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 8d4856e7bbb4b60d0f17ddb993cee2a62b40b84f
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Wed Nov 5 13:52:41 2014 +0100
allow to spawn builder in advance
>---------------------------------------------------------------
backend/backend/dispatcher.py | 30 +++++++++++++++++++-----------
backend/backend/helpers.py | 3 +++
backend/copr-be.conf.example | 5 +++++
3 files changed, 27 insertions(+), 11 deletions(-)
diff --git a/backend/backend/dispatcher.py b/backend/backend/dispatcher.py
index 3ddc781..1854175 100644
--- a/backend/backend/dispatcher.py
+++ b/backend/backend/dispatcher.py
@@ -144,6 +144,7 @@ class Worker(multiprocessing.Process):
self.callback = callback
self.create = create
self.lock = lock
+ self.spawn_in_advance = self.opts.spawn_in_advance
self.frontend_callback = FrontendCallback(opts, events)
if not self.callback:
self.logfile = os.path.join(
@@ -428,6 +429,19 @@ class Worker(multiprocessing.Process):
return True
return False
+ def __spawn_with_check(self, job):
+ """ Wrapper around self.spawn_instance() with exception checking """
+ try:
+ ip = self.spawn_instance(job)
+ if not ip:
+ raise CoprWorkerError(
+ "No IP found from creating instance")
+ except ansible.errors.AnsibleError as e:
+ self.callback.log("failure to setup instance: {0}".format(e))
+ raise
+ return ip
+
+
def run(self):
"""
Worker should startup and check if it can function
@@ -492,18 +506,10 @@ class Worker(multiprocessing.Process):
# this is our best place to sanity check the job before starting
# up any longer process
- # spin up our build instance
if self.create and not self.ip:
- try:
- ip = self.spawn_instance(job)
- if not ip:
- raise CoprWorkerError(
- "No IP found from creating instance")
-
- except ansible.errors.AnsibleError as e:
- self.callback.log(
- "failure to setup instance: {0}".format(e))
- raise
+ if not self.spawn_in_advance:
+ ip = self.__spawn_with_check(job)
+ # else we get ip from similar calling at the enf of this while-loop
else:
ip = self.ip
@@ -610,3 +616,5 @@ class Worker(multiprocessing.Process):
# clean up the instance
if self.create:
self.terminate_instance(ip)
+ if self.create and not self.ip and self.spawn_in_advance:
+ ip = self.__spawn_with_check(job)
diff --git a/backend/backend/helpers.py b/backend/backend/helpers.py
index 0992eb6..61eabb2 100644
--- a/backend/backend/helpers.py
+++ b/backend/backend/helpers.py
@@ -147,6 +147,9 @@ class BackendConfigReader(object):
opts.prune_days = _get_conf(cp, "backend", "prune_days", None, mode="int")
opts.prune_script = _get_conf(cp, "backend", "prune_script", None, mode="path")
+ opts.spawn_in_advance = _get_conf(
+ cp, "backend", "spawn_in_advance", False, mode="bool")
+
# thoughts for later
# ssh key for connecting to builders?
# cloud key stuff?
diff --git a/backend/copr-be.conf.example b/backend/copr-be.conf.example
index ff79e6d..69bcf7b 100644
--- a/backend/copr-be.conf.example
+++ b/backend/copr-be.conf.example
@@ -101,6 +101,11 @@ prune_days=14
# path to executable script to clean old build
prune_script=/usr/share/copr/copr_prune_old_builds.sh
+# Spawn builder in advance, before we get task?
+# It save time, but consume resources even when
+# nothing is in queue
+#spawn_in_advance=false
+
[builder]
# default is 1800
timeout=3600