mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2025-06-29 01:55:13 +00:00
Adjust the whole framework to event handler dependency inversion
This commit is contained in:
3
lib/tfw/main/__init__.py
Normal file
3
lib/tfw/main/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
from .tfw_connector import TFWUplinkConnector, TFWConnector
|
||||
from .event_handler_factory import EventHandlerFactory
|
||||
from .signal_handling import setup_signal_handlers
|
8
lib/tfw/main/event_handler_factory.py
Normal file
8
lib/tfw/main/event_handler_factory.py
Normal file
@ -0,0 +1,8 @@
|
||||
from tfw.event_handlers import EventHandlerFactoryBase
|
||||
|
||||
from .tfw_connector import TFWConnector
|
||||
|
||||
|
||||
class EventHandlerFactory(EventHandlerFactoryBase):
|
||||
def _build_server_connector(self):
|
||||
return TFWConnector()
|
11
lib/tfw/main/signal_handling.py
Normal file
11
lib/tfw/main/signal_handling.py
Normal file
@ -0,0 +1,11 @@
|
||||
from signal import signal, SIGTERM, SIGINT
|
||||
|
||||
from tfw.event_handlers import EventHandler
|
||||
|
||||
|
||||
def setup_signal_handlers():
|
||||
def stop(*_):
|
||||
EventHandler.stop_all_instances()
|
||||
exit(0)
|
||||
signal(SIGTERM, stop)
|
||||
signal(SIGINT, stop)
|
25
lib/tfw/main/tfw_connector.py
Normal file
25
lib/tfw/main/tfw_connector.py
Normal file
@ -0,0 +1,25 @@
|
||||
from tfw.networking import ServerConnector, ServerUplinkConnector
|
||||
from tfw.config import TFWENV
|
||||
|
||||
|
||||
class ConnAddrMixin:
|
||||
@property
|
||||
def uplink_conn_addr(self):
|
||||
return f'tcp://localhost:{TFWENV.PULL_PORT}'
|
||||
|
||||
@property
|
||||
def downlink_conn_addr(self):
|
||||
return f'tcp://localhost:{TFWENV.PUB_PORT}'
|
||||
|
||||
|
||||
class TFWUplinkConnector(ServerUplinkConnector, ConnAddrMixin):
|
||||
def __init__(self):
|
||||
super().__init__(self.uplink_conn_addr)
|
||||
|
||||
|
||||
class TFWConnector(ServerConnector, ConnAddrMixin):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
self.downlink_conn_addr,
|
||||
self.uplink_conn_addr
|
||||
)
|
Reference in New Issue
Block a user