mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 16:21:31 +00:00
35 lines
958 B
Python
35 lines
958 B
Python
import logging
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
class DeployHandler:
|
|
keys = ['deploy.start', 'process.restart']
|
|
|
|
def __init__(self, process_name='webservice'):
|
|
self.connector = None
|
|
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)
|
|
|
|
def handle_deploy(self, _):
|
|
self.connector.send_message({
|
|
'key': 'process.restart',
|
|
'name': self.process_name
|
|
})
|
|
|
|
def handle_process(self, message):
|
|
response = {'key': 'deploy.finish'}
|
|
if 'error' in message:
|
|
response['error'] = message['error']
|
|
self.connector.send_message(response)
|