From 1ee0bc66b3e82c52194308596cbb00ef4460913c Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Sun, 20 Mar 2016 13:56:59 +0000 Subject: Encapsulate builds in RequestsController Change-Id: Ied3330a1012b5b204f36b13053c2f68127b0559d --- gear/client.py | 50 +++++++++++++++++++++++++++++++++----------------- 1 file 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() -- cgit v1.2.1