workerapi.py 857 Bytes
Newer Older
Andreas Valder's avatar
Andreas Valder committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import requests
from socket import gethostname
import json


class WorkerApi(object):
	def __init__(self, baseurl,apikey):
		self.baseurl = baseurl
		self.apikey = apikey

	def worker_ping(self):
		r = requests.post(self.baseurl+'/internal/jobs/api/worker/'+gethostname()+'/ping', params={'apikey': self.apikey})
		return  r.status_code == 200

	def worker_schedule(self, jobtypes):
		r = requests.post(self.baseurl+'/internal/jobs/api/worker/'+gethostname()+'/schedule', json={'apikey': self.apikey, 'jobtypes': jobtypes})
		if r.status_code == 200:
			return r.json()
		else:
			return False
	
	def job_ping(self, id, state='running', status={}):
		r = requests.post(self.baseurl+'/internal/jobs/api/job/'+str(id)+'/ping', params={'apikey': self.apikey, 'host': gethostname(), 'state': state, 'status': json.dumps(status) })
		return r.status_code == 200