summaryrefslogtreecommitdiff
path: root/gear/client.py
blob: cfbc912d839b85e294d0910353652762e3a49ad8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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)
        print job.data[-1]
        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)