summaryrefslogtreecommitdiff
path: root/gear/worker.py
blob: 1c02a112e4922ad76a8f17ec57cd0ef60ec5a882 (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
import gear
worker = gear.Worker('reverser')
worker.addServer('localhost')
worker.registerFunction("reverse")
worker.registerFunction("build-graph")
import time
import json
from subprocess import Popen, PIPE, STDOUT


while True:
    print "waiting for job"
    job = worker.getJob()
    print "received job"
    if job.name == "reverse":
        for x in range(0, 100000):
            job.sendWorkData("This is: %s" % x)
        job.sendWorkComplete("answer")
    elif job.name == "build-graph":
        bg_request=json.loads(job.arguments)
        print "build graph!!!"
        print bg_request['repo']
        print bg_request['ref']
        print bg_request['system']
        cmd = ['morph', 'calculate-build-graph', '--quiet', bg_request['repo'], bg_request['ref'], bg_request['system']]
        print cmd
        p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
        output = p.stdout.read()
        print "finished computing build graph"
        job.sendWorkComplete(output)