29 lines
771 B
Python
29 lines
771 B
Python
#!/usr/bin/python3
|
|
|
|
import json
|
|
from urllib.request import urlopen, Request
|
|
|
|
|
|
def get_job(url="http://localhost:8898"):
|
|
"""get_job fetchs jobs from dkron"""
|
|
fullurl = f"{url}/v1/jobs"
|
|
req = Request(method="GET", url=fullurl)
|
|
res = urlopen(req)
|
|
dkron_ret = json.loads(res.read())
|
|
if res.status == 200:
|
|
return dkron_ret
|
|
return None
|
|
|
|
|
|
def set_job(url="http://localhost:8898", job=None):
|
|
"""set_job sets job in dkron"""
|
|
fullurl = f"{url}/v1/jobs"
|
|
data = json.dumps(job).encode('utf-8')
|
|
req = Request(method="POST", url=fullurl, data=data)
|
|
req.add_header('Content-Type', 'application/json')
|
|
res = urlopen(req)
|
|
dkron_ret = json.loads(res.read())
|
|
if res.status == 201:
|
|
return dkron_ret
|
|
return None
|