Add fallback for tz not being found

This commit is contained in:
amcmanu3 2022-06-13 14:29:25 -04:00
parent 0ffe6801d8
commit b3f167ab62
4 changed files with 39 additions and 13 deletions

View File

@ -9,20 +9,21 @@ from peewee import DoesNotExist
# TZLocal is set as a hidden import on win pipeline
from tzlocal import get_localzone
from tzlocal.utils import ZoneInfoNotFoundError
from apscheduler.schedulers.background import BackgroundScheduler
from app.classes.controllers.crafty_perms_controller import CraftyPermsController
from app.classes.controllers.management_controller import ManagementController
from app.classes.controllers.users_controller import UsersController
from app.classes.controllers.roles_controller import RolesController
from app.classes.controllers.server_perms_controller import ServerPermsController
from app.classes.controllers.servers_controller import ServersController
from app.classes.models.server_permissions import EnumPermissionsServer
from app.classes.shared.main_models import DatabaseShortcuts
from app.classes.models.users import HelperUsers
from app.classes.models.roles import HelperRoles
from app.classes.models.management import HelpersManagement
from app.classes.models.servers import HelperServers
from app.classes.controllers.crafty_perms_controller import CraftyPermsController
from app.classes.controllers.management_controller import ManagementController
from app.classes.controllers.users_controller import UsersController
from app.classes.controllers.roles_controller import RolesController
from app.classes.controllers.server_perms_controller import ServerPermsController
from app.classes.controllers.servers_controller import ServersController
from app.classes.shared.authentication import Authentication
from app.classes.shared.console import Console
from app.classes.shared.helpers import Helpers
@ -57,7 +58,13 @@ class Controller:
self.users: UsersController = UsersController(
self.helper, self.users_helper, self.authentication
)
tz = get_localzone()
try:
tz = get_localzone()
except ZoneInfoNotFoundError:
logger.error(
"Could not capture time zone from system. Falling back to Europe/London"
)
tz = "Europe/London"
self.support_scheduler: BackgroundScheduler = BackgroundScheduler(
timezone=str(tz)
)

View File

@ -13,6 +13,7 @@ import tempfile
# TZLocal is set as a hidden import on win pipeline
from tzlocal import get_localzone
from tzlocal.utils import ZoneInfoNotFoundError
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.jobstores.base import JobLookupError
@ -125,7 +126,11 @@ class ServerInstance:
self.stats = stats
self.server_object = HelperServers.get_server_obj(self.server_id)
self.stats_helper = HelperServerStats(self.server_id)
tz = get_localzone()
try:
tz = get_localzone()
except ZoneInfoNotFoundError:
logger.error("Could not capture time zone from system. Falling back to Europe/London")
tz = "Europe/London"
self.server_scheduler = BackgroundScheduler(timezone=str(tz))
self.server_scheduler.start()
self.backup_thread = threading.Thread(

View File

@ -4,14 +4,16 @@ import logging
import threading
import asyncio
import datetime
from tzlocal import get_localzone
from tzlocal.utils import ZoneInfoNotFoundError
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.controllers.users_controller import UsersController
from app.classes.shared.console import Console
from app.classes.shared.helpers import Helpers
from app.classes.shared.main_controller import Controller
@ -41,8 +43,11 @@ class TasksManager:
self.helper: Helpers = helper
self.controller: Controller = controller
self.tornado: Webserver = Webserver(helper, controller, self)
self.tz = get_localzone()
try:
self.tz = get_localzone()
except ZoneInfoNotFoundError:
logger.error("Could not capture time zone from system. Falling back to Europe/London")
self.tz = "Europe/London"
self.scheduler = BackgroundScheduler(timezone=str(self.tz))
self.users_controller: UsersController = self.controller.users

View File

@ -15,13 +15,14 @@ from tornado import iostream
# TZLocal is set as a hidden import on win pipeline
from tzlocal import get_localzone
from tzlocal.utils import ZoneInfoNotFoundError
from croniter import croniter
from app.classes.controllers.roles_controller import RolesController
from app.classes.models.servers import Servers
from app.classes.models.server_permissions import EnumPermissionsServer
from app.classes.models.crafty_permissions import EnumPermissionsCrafty
from app.classes.models.management import HelpersManagement
from app.classes.controllers.roles_controller import RolesController
from app.classes.shared.helpers import Helpers
from app.classes.shared.main_models import DatabaseShortcuts
from app.classes.web.base_handler import BaseHandler
@ -276,10 +277,18 @@ class PanelHandler(BaseHandler):
user_order.remove(server_id)
defined_servers = page_servers
try:
tz = get_localzone()
except ZoneInfoNotFoundError:
logger.error(
"Could not capture time zone from system. Falling back to Europe/London"
)
tz = "Europe/London"
page_data: t.Dict[str, t.Any] = {
# todo: make this actually pull and compare version data
"update_available": False,
"serverTZ": get_localzone(),
"serverTZ": tz,
"version_data": self.helper.get_version_string(),
"user_data": exec_user,
"user_role": exec_user_role,