fixing server shutdown gracefull exit

This commit is contained in:
Silversthorn 2022-05-26 15:28:54 +02:00
parent 2b484d5a07
commit be1930c7c7
2 changed files with 16 additions and 10 deletions

View File

@ -5,19 +5,23 @@ import threading
import logging
import getpass
from app.classes.shared.console import Console
from app.classes.shared.import3 import Import3
from app.classes.shared.helpers import Helpers
from app.classes.shared.tasks import TasksManager
from app.classes.shared.migration import MigrationManager
from app.classes.shared.main_controller import Controller
logger = logging.getLogger(__name__)
class MainPrompt(cmd.Cmd):
def __init__(self, helper, tasks_manager, migration_manager, main_controller):
super().__init__()
self.helper = helper
self.tasks_manager = tasks_manager
self.migration_manager = migration_manager
self.controller = main_controller
self.helper: Helpers = helper
self.tasks_manager: TasksManager = tasks_manager
self.migration_manager: MigrationManager = migration_manager
self.controller: Controller = main_controller
# overrides the default Prompt
self.prompt = f"Crafty Controller v{self.helper.get_version_string()} > "

View File

@ -8,10 +8,12 @@ from tzlocal import get_localzone
from apscheduler.events import EVENT_JOB_EXECUTED
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.cron import CronTrigger
from app.classes.controllers.users_controller import UsersController
from app.classes.models.management import HelpersManagement
from app.classes.models.users import HelperUsers
from app.classes.shared.console import Console
from app.classes.shared.helpers import Helpers
from app.classes.shared.main_controller import Controller
from app.classes.web.tornado_handler import Webserver
@ -36,14 +38,14 @@ class TasksManager:
controller: Controller
def __init__(self, helper, controller):
self.helper = helper
self.controller = controller
self.tornado = Webserver(helper, controller, self)
self.helper: Helpers = helper
self.controller: Controller = controller
self.tornado: Webserver = Webserver(helper, controller, self)
self.tz = get_localzone()
self.scheduler = BackgroundScheduler(timezone=str(self.tz))
self.users_controller = self.controller.users
self.users_controller: UsersController = self.controller.users
self.webserver_thread = threading.Thread(
target=self.tornado.run_tornado, daemon=True, name="tornado_thread"
@ -130,7 +132,7 @@ class TasksManager:
def _main_graceful_exit(self):
try:
os.remove(self.helper.session_file)
self.controller.stop_all_servers()
self.controller.servers.stop_all_servers()
except:
logger.info("Caught error during shutdown", exc_info=True)