2019-08-26 11:13:15 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2019-08-23 14:24:47 +00:00
|
|
|
class DeployHandler:
|
|
|
|
keys = ['deploy.start', 'process.restart']
|
|
|
|
|
|
|
|
def __init__(self, process_name='webservice'):
|
2019-08-28 14:40:23 +00:00
|
|
|
self.connector = None
|
2019-08-23 14:24:47 +00:00
|
|
|
self.process_name = process_name
|
|
|
|
|
|
|
|
self.commands = {
|
|
|
|
'deploy.start': self.handle_deploy,
|
|
|
|
'process.restart': self.handle_process
|
|
|
|
}
|
|
|
|
|
|
|
|
def handle_event(self, message, _):
|
|
|
|
try:
|
|
|
|
self.commands[message['key']](message)
|
|
|
|
except KeyError:
|
|
|
|
LOG.error('IGNORING MESSAGE: Invalid message received: %s', message)
|
|
|
|
|
2019-08-28 14:40:23 +00:00
|
|
|
def handle_deploy(self, _):
|
2019-08-23 14:24:47 +00:00
|
|
|
self.connector.send_message({
|
|
|
|
'key': 'process.restart',
|
|
|
|
'name': self.process_name
|
|
|
|
})
|
|
|
|
|
|
|
|
def handle_process(self, message):
|
2019-08-26 11:13:15 +00:00
|
|
|
response = {'key': 'deploy.finish'}
|
|
|
|
if 'error' in message:
|
|
|
|
response['error'] = message['error']
|
|
|
|
self.connector.send_message(response)
|