Skip to content
Snippets Groups Projects
Commit 50558148 authored by David Trattnig's avatar David Trattnig
Browse files

refactor: make scheduler bootable, remove db init

parent a856599e
No related branches found
No related tags found
1 merge request!35ORM-less scheduling
...@@ -150,6 +150,7 @@ class EngineEventDispatcher: ...@@ -150,6 +150,7 @@ class EngineEventDispatcher:
from aura_engine.scheduling.scheduler import AuraScheduler from aura_engine.scheduling.scheduler import AuraScheduler
self.scheduler = AuraScheduler(self.engine) self.scheduler = AuraScheduler(self.engine)
self.scheduler.boot()
self.call_event("on_initialized", None) self.call_event("on_initialized", None)
def on_boot(self): def on_boot(self):
......
...@@ -21,10 +21,16 @@ ...@@ -21,10 +21,16 @@
The scheduler. The scheduler.
""" """
from __future__ import annotations
import logging import logging
import threading import threading
import time import time
import aura_engine
import aura_engine.scheduling.api as api
import aura_engine.scheduling.timetable as timetable
import aura_engine.scheduling.utils as utils
from aura_engine.base.config import AuraConfig from aura_engine.base.config import AuraConfig
from aura_engine.base.utils import SimpleUtil as SU from aura_engine.base.utils import SimpleUtil as SU
from aura_engine.control import EngineExecutor from aura_engine.control import EngineExecutor
...@@ -32,9 +38,6 @@ from aura_engine.core.channels import LoadSourceException ...@@ -32,9 +38,6 @@ from aura_engine.core.channels import LoadSourceException
from aura_engine.engine import Engine, Player from aura_engine.engine import Engine, Player
from aura_engine.resources import ResourceClass, ResourceUtil from aura_engine.resources import ResourceClass, ResourceUtil
from aura_engine.scheduling.domain import PlaylistItem from aura_engine.scheduling.domain import PlaylistItem
from aura_engine.scheduling.models import AuraDatabaseModel
from aura_engine.scheduling.timetable import TimetableService
from aura_engine.scheduling.utils import TimetableRenderer
class NoActiveTimeslotException(Exception): class NoActiveTimeslotException(Exception):
...@@ -55,37 +58,41 @@ class AuraScheduler(threading.Thread): ...@@ -55,37 +58,41 @@ class AuraScheduler(threading.Thread):
""" """
config: AuraConfig = None config: AuraConfig
logger = None logger: logging.Logger
engine: Engine = None engine: Engine
exit_event: threading.Event = None timetable: timetable.TimetableService
timetable_renderer: TimetableRenderer = None timetable_renderer: utils.TimetableRenderer
timetable: TimetableService = None exit_event: threading.Event
message_timer = [] is_initialized: bool
is_initialized: bool = None is_engine_ready: bool
is_engine_ready: bool = None
def __init__(self, engine: aura_engine):
def __init__(self, engine):
self.config = AuraConfig.config() self.config = AuraConfig.config()
self.logger = logging.getLogger("engine") self.logger = logging.getLogger("engine")
self.timetable = TimetableService() self.timetable = timetable.TimetableService(self.config.get("cache_dir"))
self.timetable_renderer = TimetableRenderer(self) self.timetable_renderer = utils.TimetableRenderer(self)
self.engine = engine self.engine = engine
self.engine.scheduler = self self.engine.scheduler = self
self.is_soundsytem_init = False self.is_soundsytem_init = False
# Scheduler Initialization # Scheduler Initialization
AuraDatabaseModel.init_database() self.exit_event = None
self.is_initialized = False self.is_initialized = False
self.is_engine_ready = False self.is_engine_ready = False
def boot(self):
"""
Start the scheduler in a thread.
"""
# Init scheduling thread # Init scheduling thread
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.exit_event = threading.Event() self.exit_event = threading.Event()
self.start() self.start()
def run(self): def run(self):
"""Execute the scheduler. """
Execute the scheduler.
Called when thread is started via `start()`. It does the following: Called when thread is started via `start()`. It does the following:
...@@ -107,7 +114,7 @@ class AuraScheduler(threading.Thread): ...@@ -107,7 +114,7 @@ class AuraScheduler(threading.Thread):
self.logger.info(SU.cyan(msg)) self.logger.info(SU.cyan(msg))
# Load some stuff from the API in any case # Load some stuff from the API in any case
self.timetable.refresh() self.timetable.refresh(api.ApiFetcher())
# Queue only when the engine is ready to play # Queue only when the engine is ready to play
if self.is_initialized: if self.is_initialized:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment