-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExternalTaskScript.py
More file actions
31 lines (27 loc) · 838 Bytes
/
ExternalTaskScript.py
File metadata and controls
31 lines (27 loc) · 838 Bytes
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 requests
import json
url_base = 'http://localhost:8080/rest'
headers= {"Accept":"application/json", "Content-type": "application/json"}
url = url_base + '/external-task/fetchAndLock'
data = '''{
"workerId": "user",
"maxTasks": "5",
"topics": [
{
"topicName": "software_installieren",
"lockDuration": 120000
}
]
}'''
response = requests.post(url, headers=headers, data=data)
# For successful API call, response code will be 200 (OK)
if(response.ok):
jdata = json.loads(response.content)
data = '{ "workerId": "user" }'
# iterate array
for item in jdata:
print('** Completing task: ' + str(item['id']) )
url = url_base + '/external-task/' + item['id'] + '/complete'
response = requests.post(url,headers=headers, data=data)
else:
print('**No tasks available, HTTP status: ' + str(response.status_code))