summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-03-20 13:56:59 +0000
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-03-27 11:53:02 +0000
commit1ee0bc66b3e82c52194308596cbb00ef4460913c (patch)
treeaa9fda0c1102f9d5f45cb9e7720da1bfb68fba42
parent4443bd116899e3e62bbd3e4ec8e3e767a08b0c9c (diff)
downloadmorph-1ee0bc66b3e82c52194308596cbb00ef4460913c.tar.gz
Encapsulate builds in RequestsController
Change-Id: Ied3330a1012b5b204f36b13053c2f68127b0559d
-rw-r--r--gear/client.py50
1 files changed, 33 insertions, 17 deletions
diff --git a/gear/client.py b/gear/client.py
index d14edd31..d82eb86f 100644
--- a/gear/client.py
+++ b/gear/client.py
@@ -19,7 +19,7 @@ logging.basicConfig()
gear.Server()
-class theController():
+class SingleBuildController():
def __init__(self):
self.lock = threading.Lock()
self.graph_client = BuildGraphClient(self)
@@ -34,6 +34,10 @@ class theController():
self.artifact = None
self.build_started = False
+ def start_build(self, request):
+ job = gear.Job("build-graph", request)
+ self.graph_client.submitJob(job)
+
def _process_build_graph(self, build_graph):
print "Decoding artifact received"
try:
@@ -263,27 +267,39 @@ class BuilderClient(gear.Client):
job.data = []
return job
-controller = theController()
-client = controller.graph_client
-#job = gear.Job("reverse", "test string")
-build_graph_request = {}
-build_graph_request['repo'] = "baserock:baserock/definitions"
-build_graph_request['ref'] = "fbce45e45da79e5c35341845ec3b3d7c321e6ff2"
-build_graph_request['system'] = "systems/minimal-system-x86_64-generic.morph"
+class RequestsController():
+ def __init__(self):
+ self.build_requests = []
+
+ def add_request(self, request):
+ json_request = json.dumps(request)
+ request_data = {}
+ request_data['controller'] = SingleBuildController()
+ # TODO: is this the right place to do this?
+ request_data['controller'].start_build(json_request)
+ request_data['request'] = request
+ self.build_requests.append(request_data)
+
+ def queue_if_possible(self):
+ # TODO: check all of them in a loop?
+ controller = self.build_requests[0]['controller']
+ if controller.artifact != None and controller.build_started == True:
+ to_build = controller.find_artifacts_that_are_ready_to_build(
+ controller.artifact)
+ controller._queue_worker_builds(to_build)
+
-s=json.dumps(build_graph_request)
-print "Json produced: "
-print s
+request = {}
+request['repo'] = "baserock:baserock/definitions"
+request['ref'] = "fbce45e45da79e5c35341845ec3b3d7c321e6ff2"
+request['system'] = "systems/minimal-system-x86_64-generic.morph"
+requests_controller = RequestsController()
+requests_controller.add_request(request)
-job = gear.Job("build-graph", s)
-client.submitJob(job)
# loop so that client doesn't die
while True:
import time
time.sleep(0.0001)
- if controller.artifact != None and controller.build_started == True:
- to_build = controller.find_artifacts_that_are_ready_to_build(
- controller.artifact)
- controller._queue_worker_builds(to_build)
+ requests_controller.queue_if_possible()