Compare commits

..
12 changed files with 61 additions and 25 deletions
+6 -2
View File
@@ -1,5 +1,9 @@
FROM avatao/frontend-tutorial-framework:chausie-20191014 as frontend
ARG FRONTEND_VERSION
FROM avatao/frontend-tutorial-framework:${FRONTEND_VERSION} as frontend
FROM avatao/debian:buster
ARG FRONTEND_VERSION
LABEL tfw.frontend.version=${FRONTEND_VERSION}
RUN apt-get update &&\
apt-get install -y --no-install-recommends \
@@ -69,7 +73,7 @@ ONBUILD COPY ${BUILD_CONTEXT}/supervisor/ ${TFW_SUPERVISORD_COMPONENTS}
ONBUILD RUN for f in "${TFW_NGINX_DEFAULT}" ${TFW_NGINX_COMPONENTS}/*.conf; do \
envsubst "$(printenv | cut -d= -f1 | grep TFW_ | sed -e 's/^/$/g')" < $f > $f~ && mv $f~ $f ;\
done
ONBUILD VOLUME ["/etc/nginx", "/var/lib/nginx", "/var/log/nginx", "${TFW_LIB_DIR}/tfw"]
ONBUILD VOLUME ["/etc/nginx", "/etc/supervisor", "/var/lib/nginx", "/var/log/nginx", "${TFW_LIB_DIR}/tfw"]
ENTRYPOINT ["/bin/init", "--"]
CMD exec supervisord --nodaemon --configuration ${TFW_SUPERVISORD_CONF}
+2 -2
View File
@@ -1,6 +1,6 @@
from os.path import dirname, realpath, join
from setuptools import setup
from setuptools import setup, find_packages
here = dirname(realpath(__file__))
@@ -17,7 +17,7 @@ setup(
author='Avatao.com Innovative Learning Kft.',
author_email='support@avatao.com',
license='custom',
packages=['tfw'],
packages=find_packages(),
package_dir={'tfw': 'tfw'},
install_requires=requirements,
extras_require={
+1
View File
@@ -4,3 +4,4 @@ directory=/tmp
command=bash tfw_init.sh
autorestart=false
startsecs=0
priority=1
+1
View File
@@ -2,3 +2,4 @@
user=root
directory=%(ENV_TFW_SERVER_DIR)s
command=python3 -u tfw_server.py
priority=2
@@ -12,7 +12,7 @@ class FrontendConfigHandler:
def handle_event(self, _, connector):
# pylint: disable=no-self-use
for message in self._config_messages:
connector.send_message(message)
connector.send_message(message, scope=Scope.WEBSOCKET)
connector.send_message({'key': 'frontend.ready'}, scope=Scope.WEBSOCKET)
@property
@@ -16,10 +16,13 @@ class ProcessLogHandler:
self._initial_log_tail = log_tail
self.command_handlers = {
'process.log.set': self.handle_set
'process.log.set': self.handle_set,
'process.log.start': self.handle_start,
'process.log.stop': self.handle_stop
}
def start(self):
if not self._monitor:
self._monitor = LogInotifyObserver(
connector=self.connector,
process_name=self.process_name,
@@ -40,5 +43,16 @@ class ProcessLogHandler:
if data.get('tail'):
self._monitor.log_tail = data['tail']
def cleanup(self):
def handle_start(self, _):
self.start()
def handle_stop(self, _):
self._stop_monitor()
def _stop_monitor(self):
if self._monitor:
self._monitor.stop()
self._monitor = None
def cleanup(self):
self._stop_monitor()
@@ -17,7 +17,7 @@ class TerminadoMiniServer:
url,
TerminadoMiniServer.ResetterTermSocket,
{'term_manager': self._term_manager}
)])
)], websocket_ping_interval=30)
@property
def term_manager(self):
@@ -42,6 +42,9 @@ class TerminalHandler:
LOG.error('IGNORING MESSAGE: Invalid message received: %s', message)
def handle_write(self, message):
concat = message.get('concat', False)
if not concat:
self.terminado_server.pty.write('\x15')
self.terminado_server.pty.write(message['command'])
def cleanup(self):
+3 -4
View File
@@ -1,6 +1,7 @@
import logging
from collections import defaultdict
from datetime import datetime
from contextlib import suppress
from transitions import Machine, MachineError
@@ -62,14 +63,12 @@ class FSMBase(Machine, CallbackMixin):
)
if all(predicate_results):
try:
with suppress(AttributeError, MachineError):
from_state = self.state
self.trigger(trigger)
if self.trigger(trigger):
self.update_event_log(from_state, trigger)
return True
except (AttributeError, MachineError):
LOG.debug('FSM failed to execute nonexistent trigger: "%s"', trigger)
return False
def update_event_log(self, from_state, trigger):
self.event_log.append({
+14 -1
View File
@@ -42,7 +42,8 @@ def deserialize_tfw_msg(*args):
"""
Return message from TFW multipart data
"""
return _deserialize_all(*args)[1]
envelope = _deserialize_all(*args)
return _repair_if_needed(envelope)
def _serialize_all(*args):
@@ -84,6 +85,18 @@ def _deserialize_single(data):
return _decode_if_needed(data)
def _repair_if_needed(envelope):
"""
Quick fix for broken messages received from separate processes.
"""
if len(envelope) == 2:
return envelope[1]
for part in envelope:
if isinstance(part, dict):
return part
return {}
def _encode_if_needed(value):
"""
Return input as bytes
+2 -1
View File
@@ -2,6 +2,7 @@
from datetime import datetime
from typing import TextIO, Union
from dataclasses import dataclass
from collections.abc import Mapping
from traceback import format_exception
from logging import DEBUG, getLogger, Handler, Formatter, Filter
@@ -81,7 +82,7 @@ class LogFormatter(Formatter):
def format(self, record):
time = datetime.utcfromtimestamp(record.created).strftime('%H:%M:%S')
if record.args:
tuple_args = (record.args,) if isinstance(record.args, dict) else record.args
tuple_args = (record.args,) if isinstance(record.args, Mapping) else record.args
clean_args = tuple((self.trim(arg) for arg in tuple_args))
message = record.msg % clean_args
else:
+1 -1
View File
@@ -28,7 +28,7 @@ class TFWServer:
r'/ws', ZMQWebSocketRouter, {
'listener': self._listener,
}
)])
)], websocket_ping_interval=30)
def listen(self):
self.application.listen(TFWENV.WEB_PORT)