This commit is contained in:
flaskfarm
2022-10-14 19:28:28 +09:00
parent 15eef1f91a
commit adac0f59ed
5 changed files with 23 additions and 17 deletions

View File

@@ -1,3 +1,4 @@
import os
from functools import wraps
from flask import abort, request
@@ -45,14 +46,15 @@ class CustomFormatter(logging.Formatter):
green = "\x1B[32m"
# pathname filename
#format = "[%(asctime)s|%(name)s|%(levelname)s - %(message)s (%(filename)s:%(lineno)d)"
format = '[{yellow}%(asctime)s{reset}|{color}%(levelname)s{reset}|{green}%(name)s{reset} %(pathname)s:%(lineno)s] {color}%(message)s{reset}'
__format = '[{yellow}%(asctime)s{reset}|{color}%(levelname)s{reset}|{green}%(name)s{reset} %(pathname)s:%(lineno)s] {color}%(message)s{reset}' if os.environ.get('LOGGER_PATHNAME', "False") == "True" else '[{yellow}%(asctime)s{reset}|{color}%(levelname)s{reset}|{green}%(name)s{reset} %(filename)s:%(lineno)s] {color}%(message)s{reset}'
FORMATS = {
logging.DEBUG: format.format(color=grey, reset=reset, yellow=yellow, green=green),
logging.INFO: format.format(color=green, reset=reset, yellow=yellow, green=green),
logging.WARNING: format.format(color=yellow, reset=reset, yellow=yellow, green=green),
logging.ERROR: format.format(color=red, reset=reset, yellow=yellow, green=green),
logging.CRITICAL: format.format(color=bold_red, reset=reset, yellow=yellow, green=green)
logging.DEBUG: __format.format(color=grey, reset=reset, yellow=yellow, green=green),
logging.INFO: __format.format(color=green, reset=reset, yellow=yellow, green=green),
logging.WARNING: __format.format(color=yellow, reset=reset, yellow=yellow, green=green),
logging.ERROR: __format.format(color=red, reset=reset, yellow=yellow, green=green),
logging.CRITICAL: __format.format(color=bold_red, reset=reset, yellow=yellow, green=green)
}
def format(self, record):

View File

@@ -253,8 +253,8 @@ class Framework:
self.config['path_app'] = self.config['path_app'][0].upper() + self.config['path_app'][1:]
self.path_app_root = self.config['path_app']
self.config['path_working'] = os.getcwd()
if os.environ.get('RUNNING_TYPE') == 'docker':
self.config['running_type'] = 'docker'
if os.environ.get('RUNNING_TYPE', None) != None:
self.config['running_type'] = os.environ.get('RUNNING_TYPE')
self.config['export_filepath'] = os.path.join(self.config['path_app'], 'export.sh')
self.config['exist_export'] = os.path.exists(self.config['export_filepath'])
self.__process_args()
@@ -262,13 +262,15 @@ class Framework:
self.__init_define()
self.config['menu_yaml_filepath'] = os.path.join(self.config['path_data'], 'db', 'menu.yaml')
self.config['notify_yaml_filepath'] = os.path.join(self.config['path_data'], 'db', 'notify.yaml')
if 'running_type' not in self.config:
self.config['running_type'] = 'native'
elif mode == "flask":
self.app.secret_key = os.urandom(24)
self.app.config['TEMPLATES_AUTO_RELOAD'] = True
self.app.config['JSON_AS_ASCII'] = False
elif mode == 'system_loading_after':
if 'running_type' not in self.config:
self.config['running_type'] = 'native'
pass
def __init_define(self):
@@ -316,8 +318,7 @@ class Framework:
# celery는 환경변수 사용불가로 native 판단
# 도커는 celery가 먼저 진입
# 추후에 변경할 것!!!!!!!!!!!!!!!!! TODO
#if self.config.get('running_type') == 'docker':
if self.config.get('running_type') == 'docker':# or os.path.exists('/data'):
if self.config.get('running_type').startswith('docker'):# or os.path.exists('/data'):
shutil.copy(
os.path.join(self.path_app_root, 'files', 'config.yaml.docker'),
self.config['config_filepath']
@@ -452,7 +453,7 @@ class Framework:
def start(self):
host = '0.0.0.0'
for i in range(10):
for i in range(5):
try:
#self.logger.debug(d(self.config))
# allow_unsafe_werkzeug=True termux nohup 실행시 필요함
@@ -477,6 +478,9 @@ class Framework:
continue
except KeyboardInterrupt:
self.logger.error('KeyboardInterrupt !!')
except:
self.logger.error("start error")
#except SystemExit:
# return
#sys.exit(self.__exit_code)

View File

@@ -1 +1 @@
VERSION="4.0.5"
VERSION="4.0.6"

View File

@@ -36,8 +36,8 @@ class ModuleSetting(PluginModuleBase):
'notify_advaned_use' : 'False',
'notify.yaml': '', #직접 사용하지 않으나 저장 편의상.
'command_text': '',
'celery_start_by_web': 'False', #웹 실행시 celery 실행
'celery_start_command': "celery -A flaskfarm.main.celery worker --loglevel=info --pool=gevent --concurrency=2 --config_filepath={F.config['config_filepath']} --running_type=native",
'celery_start_by_web': 'True' if F.config['running_type'] == 'docker_alpine' else 'False', #웹 실행시 celery 실행
'celery_start_command': f"celery -A flaskfarm.main.celery worker --loglevel=info --pool=gevent --concurrency=2 --config_filepath={F.config['config_filepath']} --running_type={F.config['running_type']}",
}

View File

@@ -34,7 +34,7 @@ var running_type = "{{arg['running_type']}}";
$(document).ready(function(){
console.log(running_type);
if (running_type == 'docker') {
if (running_type.startsWith('docker')) {
$('#celery_start_by_web').bootstrapToggle('off');
$('#celery_start_by_web').prop('disabled', true);
}