-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
45 lines (34 loc) · 1.18 KB
/
test.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
import nomad
import logging
import json
import time
loggers = {}
NOMAD_HOST = "localhost"
def setup_custom_logger(name, log_level=logging.DEBUG):
if loggers.get(name):
return loggers[name]
logger = logging.getLogger(name)
loggers[name] = logger
formatter = logging.Formatter(fmt='%(asctime)s - %(levelname)s - %(module)s - line %(lineno)d - %(message)s')
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.setLevel(log_level)
logger.addHandler(handler)
return logger
logger = setup_custom_logger('root')
# checking if nomad is running
n = nomad.Nomad(host=NOMAD_HOST, timeout=5)
status = n.status
logger.info("Nomad status is %s" % status)
# get the job definition from file
file = open("./job-definitions/fake_news_detection.json")
job_definition = json.load(file)
#spinning the fake_news_detector workflow
register = n.job.register_job("fake_news_detection", job_definition)
logger.debug("Registered job %s" % register)
time.sleep(1)
deployment = n.job.get_deployment("fake_news_detection")
logger.debug("Deployments: %s" % deployment)
# getting the result
# deregistering the job
#n.job.deregister_job("fake_news_detector")