-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.py
executable file
·69 lines (60 loc) · 2.01 KB
/
worker.py
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
67
68
69
#!/usr/bin/env python
import requests
import json
import sys
import time
import random
import imp
from submitty import *
api = 'https://cmage109g3.execute-api.us-west-2.amazonaws.com/what'
worker_ready = api+'/worker-bee/ready'
worker_done = api+'/worker-bee/done'
def workfake(worker):
while(True):
response = requests.post(worker_ready, json.dumps({'name': worker})).text
response = json.loads(response)
if ('work' not in response.keys()):
print "Error: "+json.dumps(response)
time.sleep(10)
continue
if (response['work']):
group = response['group']
version = response['version']
print '*** work, running '+group+" version "+version,
if (group == 'submitty'):
info = response['requestinfo']
print "raw response :" + info
try:
info2 = json.loads(info)
tags = []
for i in range(0, len(info2)):
info3 = info2[i]
tag = submitter(info3['problemId'], info3['seed'], info3['tag'],
info3['solution'], group)
tags.append(tag)
response_info = {
'tag': {'SS': tags}
}
except:
print "It didn't work: "^info
else:
print 'version '+response['version']
time.sleep(15)
response_info = {
'Greeting': {'S': 'hello'},
'Random': {'S': str(random.random())}
}
response = requests.post(worker_done, json.dumps({
'name': worker,
'group': group,
'version': version,
'result': response_info
}))
else:
print '*** no work, sleeping for '+str(response['wait'])
time.sleep(response['wait'])
if __name__ == "__main__":
if not (len(sys.argv) == 2):
print "Usage: ./fake-worker.py WORKERNAME"
sys.exit(1)
workfake(sys.argv[1])