-
Notifications
You must be signed in to change notification settings - Fork 55
/
gearmanjobstop.py
59 lines (51 loc) · 1.64 KB
/
gearmanjobstop.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
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import sys
import os
import time
import json
from lib.logLib import *
from lib.cmdLib import *
from lib.sftpLib import *
from lib.mysqlLib import *
import jenkinsapi
from jenkinsapi.jenkins import Jenkins
from jenkinsapi.jobs import Jobs
from jenkinsapi.job import Job
from jenkinsapi.build import Build
import gear
gear_server = "cq01-rdqa-pool094.cq01.baidu.com"
gear_port = 8899
def gearmanjobstop(unique_id):
datalist_info = {}
output = None
try:
client = gear.Client()
client.addServer(gear_server, port = gear_port)
client.waitForServer() # Wait for at least one server to be connected
param={"id":unique_id}
mysql=mysqlLib()
datalist=mysql.query_task(param)
mysql.close()
jobname = datalist[0][3]
status = datalist[0][5]
build_number = datalist[0][6]
if (int(status) == 2):
build_params = {"name":jobname, "number":str(build_number)}
job = gear.Job("stop:" + gear_server, json.dumps(build_params))
client.submitJob(job)
print("INFO, job aborte start")
output = "INFO, job aborte start"
else:
print("INFO, job not running now")
output = "INFO, job not running now"
except Exception as e:
print(e)
output = "ERROR, " + str(e)
finally:
datalist_info['output'] = output
return datalist_info
if __name__ == '__main__':
unique_id = sys.argv[1]
datalist_info = gearmanjobstop(unique_id)
print json.dumps(datalist_info)