diff options
author | Pedro Alvarez <pedro.alvarez@codethink.co.uk> | 2016-03-28 17:43:05 +0000 |
---|---|---|
committer | Pedro Alvarez <pedro.alvarez@codethink.co.uk> | 2016-03-28 17:43:05 +0000 |
commit | 15c3e24302d176b5f582ad0f06270dd87c7f5655 (patch) | |
tree | 4a5dc4ff0401652037fc3869715bfe22a5ea1f2d | |
parent | c9426219a8f522d0834e9e5ca2b0385f61e0663b (diff) | |
download | morph-15c3e24302d176b5f582ad0f06270dd87c7f5655.tar.gz |
Add initial fake client for one request
Change-Id: I51be9f05ed0ae05de32f74f41bd0a62c8dffe2f8
-rw-r--r-- | gear/client.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/gear/client.py b/gear/client.py new file mode 100644 index 00000000..29c0df93 --- /dev/null +++ b/gear/client.py @@ -0,0 +1,65 @@ +import gear +import sys +import json +import threading +import requests +import time +import signal +import urlparse +import distbuild +#TODO: values from settings +cache_server = 'http://cache.baserock.org:8080' + +# Artifact build states. These are used to loosely track the state of the +# remote cache. +UNBUILT = 'not-built' +BUILDING = 'building' +BUILT = 'built' + +import logging +logging.basicConfig() + +class GearRequestClient(gear.Client): + def __init__(self): + super(GearRequestClient, self).__init__() + self.finished = False + + def handleWorkComplete(self, packet): + job = super(GearRequestClient, self).handleWorkComplete(packet) + print "Build workcomplete" + self.controller._mark_artifact_as_built(job.data[-1]) + self.finished = True + return job + + def handleWorkFailed(self, packet): + job = super(GearRequestClient, self).handleWorkFailed(packet) + print "Build workfailed" + self.controller._mark_artifact_as_built(job.data[-1]) + self.finished = True + return job + + def handleWorkData(self, packet): + job = super(GearRequestClient, self).handleWorkData(packet) + job.data = [] + return job + +request = {} +request['repo'] = "baserock:baserock/definitions" +request['ref'] = "fbce45e45da79e5c35341845ec3b3d7c321e6ff2" +request['system'] = "systems/minimal-system-x86_64-generic.morph" +json_request = json.dumps(request) +print json_request + +gear_request_client = GearRequestClient() +gear_request_client.addServer('localhost') +gear_request_client.waitForServer() +job = gear.Job("build-request", json_request) +gear_request_client.submitJob(job) + +while not gear_request_client.finished: + try: + print "waiting" + time.sleep(3) + except KeyboardInterrupt: + print "Ctrl + C: asking tasks to exit nicely...\n" + exit(0) |