mirror of
https://github.com/bunny-lab-io/Borealis.git
synced 2025-12-16 04:05:48 -07:00
Port scheduler and migrations into Engine
This commit is contained in:
1847
Data/Engine/services/API/scheduled_jobs/job_scheduler.py
Normal file
1847
Data/Engine/services/API/scheduled_jobs/job_scheduler.py
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
# ======================================================
|
||||
# Data\Engine\services\API\scheduled_jobs\management.py
|
||||
# Description: Integrates the legacy job scheduler for CRUD operations within the Engine API.
|
||||
# Description: Integrates the Engine job scheduler for CRUD operations within the Engine API.
|
||||
#
|
||||
# API Endpoints (if applicable):
|
||||
# - GET /api/scheduled_jobs (Token Authenticated) - Lists scheduled jobs with summary metadata.
|
||||
@@ -19,36 +19,18 @@ from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
try: # pragma: no cover - legacy module import guard
|
||||
import job_scheduler as legacy_job_scheduler # type: ignore
|
||||
except Exception as exc: # pragma: no cover - runtime guard
|
||||
legacy_job_scheduler = None # type: ignore
|
||||
_SCHEDULER_IMPORT_ERROR = exc
|
||||
else:
|
||||
_SCHEDULER_IMPORT_ERROR = None
|
||||
from . import job_scheduler
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover - typing aide
|
||||
from flask import Flask
|
||||
|
||||
from .. import EngineServiceAdapters
|
||||
|
||||
|
||||
def _raise_scheduler_import() -> None:
|
||||
if _SCHEDULER_IMPORT_ERROR is not None:
|
||||
raise RuntimeError(
|
||||
"Legacy job scheduler module could not be imported; ensure Data/Server/job_scheduler.py "
|
||||
"remains available during the Engine migration."
|
||||
) from _SCHEDULER_IMPORT_ERROR
|
||||
|
||||
|
||||
def ensure_scheduler(app: "Flask", adapters: "EngineServiceAdapters"):
|
||||
"""Instantiate the legacy job scheduler and attach it to the Engine context."""
|
||||
"""Instantiate the Engine job scheduler and attach it to the Engine context."""
|
||||
|
||||
if getattr(adapters.context, "scheduler", None) is not None:
|
||||
return adapters.context.scheduler
|
||||
|
||||
_raise_scheduler_import()
|
||||
|
||||
socketio = getattr(adapters.context, "socketio", None)
|
||||
if socketio is None:
|
||||
raise RuntimeError("Socket.IO instance is required to initialise the scheduled job service.")
|
||||
@@ -56,7 +38,7 @@ def ensure_scheduler(app: "Flask", adapters: "EngineServiceAdapters"):
|
||||
database_path = adapters.context.database_path
|
||||
script_signer = adapters.script_signer
|
||||
|
||||
scheduler = legacy_job_scheduler.register(
|
||||
scheduler = job_scheduler.register(
|
||||
app,
|
||||
socketio,
|
||||
database_path,
|
||||
@@ -64,7 +46,7 @@ def ensure_scheduler(app: "Flask", adapters: "EngineServiceAdapters"):
|
||||
)
|
||||
scheduler.start()
|
||||
adapters.context.scheduler = scheduler
|
||||
adapters.service_log("scheduled_jobs", "legacy scheduler initialised", level="INFO")
|
||||
adapters.service_log("scheduled_jobs", "engine scheduler initialised", level="INFO")
|
||||
return scheduler
|
||||
|
||||
|
||||
@@ -76,7 +58,7 @@ def get_scheduler(adapters: "EngineServiceAdapters"):
|
||||
|
||||
|
||||
def register_management(app: "Flask", adapters: "EngineServiceAdapters") -> None:
|
||||
"""Ensure scheduled job routes are registered via the legacy scheduler."""
|
||||
"""Ensure scheduled job routes are registered via the Engine scheduler."""
|
||||
|
||||
ensure_scheduler(app, adapters)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user