Commit ee371d0d authored by Fotis Paraskevopoulos's avatar Fotis Paraskevopoulos
Browse files

Improving init and shutdown

parent 6d834800
......@@ -12,11 +12,13 @@ class Connection:
def __init__(self, username, password,
host='localhost',
port=61613,
debug=False):
debug=False,
**kwargs):
self.username = username
self.password = password
self.hosts = [(host, port)]
self.conn = stomp.Connection(host_and_ports=self.hosts, auto_content_length=False)
self.conn = stomp.Connection(host_and_ports=self.hosts, auto_content_length=False,
timeout=kwargs.get('timeout',180000),keepalive=kwargs.get('keepalive', True))
if debug:
logging.debug("Enabling debug")
......
......@@ -21,7 +21,9 @@ class ESHybrid(morphemic.handler.ModelHandler,messaging.listener.MorphemicListen
config['messaging']['username'],
config['messaging']['password'],
host=config['messaging']['host'],
port=config['messaging']['port']
port=config['messaging']['port'],
timeout=6000,
keepalive=True
)
self.model = morphemic.model.Model(self)
self.application = config['persistence']['application']
......@@ -60,10 +62,6 @@ class ESHybrid(morphemic.handler.ModelHandler,messaging.listener.MorphemicListen
self.run()
pass
def cleanup(self):
logging.debug("Cleaning Up...")
scheduler=False
pass
def signal_handler(self, signum, frame):
logging.debug("SIGHUP")
......@@ -72,7 +70,7 @@ class ESHybrid(morphemic.handler.ModelHandler,messaging.listener.MorphemicListen
def stop(self):
logging.debug("Stopping...")
self._run = False
self.cleanup()
self.connector.disconnect()
def start(self):
logging.debug("Starting ESHybrid")
......@@ -86,6 +84,7 @@ class ESHybrid(morphemic.handler.ModelHandler,messaging.listener.MorphemicListen
self.scheduler.check(self)
time.sleep(1)
def on_schedule(self, times):
for m in self.metrics:
......@@ -107,21 +106,20 @@ class ESHybrid(morphemic.handler.ModelHandler,messaging.listener.MorphemicListen
)
# for p in predictions[m['metric']]:
def on_train(self):
self.connector.send_to_topic("training_models",
{
"metrics": self.metrics,
"forecasting_method": self.id,
"timestamp": int(time.time() * 1000)
})
def _train_model(self):
self.dataset.make()
data = self.dataset.getData()
self.model.train(self.metrics, data)
def on_train(self):
self.connector.send_to_topic("training_models",
{
"metrics": self.metrics,
"forecasting_method": self.id,
"timestamp": int(time.time() * 1000)
})
def on_metrics_to_predict(self,res):
logging.debug("[2] Metrics to predics %s " % res)
......@@ -166,14 +164,14 @@ class ESHybrid(morphemic.handler.ModelHandler,messaging.listener.MorphemicListen
horizon= res[messaging.events.StartForecasting.PREDICTION_HORIZON]
)
def on_error(self, headers, body):
logging.error("Headers %s",headers)
logging.error(" %s",body)
def on_disconnected(self):
print('disconnected')
self.reconnect()
if self._run:
self.reconnect()
def on(self, headers, res):
......
......@@ -15,9 +15,7 @@ def main():
print("Config file %s ", config_file)
config = configparser.RawConfigParser()
config.read(config_file)
config_dict = dict(config)
e = eshybrid.ESHybrid(config)
e = eshybrid.ESHybrid(dict(config))
try:
e.start()
except KeyboardInterrupt:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment