1
0
mirror of https://github.com/avatao-content/test-tutorial-framework synced 2024-12-05 02:21:31 +00:00

Add FSMAwareEH example to event_handler_main

This commit is contained in:
Kristóf Tóth 2018-07-20 13:37:22 +02:00
parent d23771e7ca
commit 2f60ddd46a

View File

@ -3,7 +3,7 @@ from functools import partial
from tornado.ioloop import IOLoop
from tfw import YamlFSM
from tfw import YamlFSM, FSMAwareEventHandler
from tfw.components import IdeEventHandler, TerminalEventHandler
from tfw.components import ProcessManagingEventHandler, BashMonitor
from tfw.components import TerminalCommands, LogMonitoringEventHandler
@ -13,8 +13,6 @@ from tfw.config import TFWENV
from tfw.config.logs import logging
from tao.config import TAOENV
from test_fsm import TestFSM
LOG = logging.getLogger(__name__)
@ -80,7 +78,27 @@ class TestCommands(TerminalCommands):
})
class MessageFSMStepsEventHandler(FSMAwareEventHandler):
"""
This example EventHandler is capable of detecting FSM state.
!! Please remove from production code !!
"""
def handle_event(self, message):
pass
def handle_fsm_step(self, from_state, to_state, trigger):
"""
When the FSM steps this method is invoked.
"""
MessageSender().send(
'FSM info',
f'FSM has stepped from state "{from_state}" '
f'to state "{to_state}" in response to trigger "{trigger}"'
)
if __name__ == '__main__':
# TFW component EventHandlers (builtins, required for their respective functionalities)
fsm = FSMManagingEventHandler( # TFW FSM
key='fsm',
fsm_type=partial(YamlFSM, 'test_fsm.yml')
@ -105,14 +123,22 @@ if __name__ == '__main__':
process_name='webservice',
log_tail=2000
)
eventhandlers = {fsm, ide, terminal, processmanager, logmonitor}
# Your custom event handlers
message_fsm_steps = MessageFSMStepsEventHandler(
key='test'
)
# Terminal command handlers
commands = TestCommands(bashrc=f'/home/{TAOENV.USER}/.bashrc')
terminal.historymonitor.subscribe_callback(commands.callback)
# Example terminal command callback
terminal.historymonitor.subscribe_callback(cenator)
try:
IOLoop.instance().start()
finally:
eventhandlers = {fsm, ide, terminal, processmanager, logmonitor, message_fsm_steps}
for eh in eventhandlers:
eh.cleanup()