fix(translate,automation): fix schedule import/param errors, add translation schedules to Automation view
- Fix ModuleNotFoundError: 4 lazy imports in _schedule_routes.py changed from 3-dot to 4-dot relative imports (src.api.dependencies -> src.dependencies) - Fix TypeError: update_schedule() param name mismatch (timezone -> timezone_str) - Add add_translation_job/remove_translation_job to SchedulerService to register translation schedules with APScheduler via execute_scheduled_translation - Add GET /settings/automation/translation-schedules endpoint returning all translation schedules with joined job names - Update Automation settings page to display translation schedules (cron, timezone, active badge, last run) below validation policies
This commit is contained in:
@@ -25,7 +25,9 @@ from ...schemas.settings import (
|
||||
ValidationPolicyCreate,
|
||||
ValidationPolicyUpdate,
|
||||
ValidationPolicyResponse,
|
||||
TranslationScheduleItem,
|
||||
)
|
||||
from ...models.translate import TranslationSchedule, TranslationJob
|
||||
from ...core.database import get_db
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
@@ -598,4 +600,40 @@ async def delete_validation_policy(
|
||||
|
||||
# #endregion delete_validation_policy
|
||||
|
||||
|
||||
# #region get_translation_schedules [C:2] [TYPE Function]
|
||||
# @BRIEF Lists all translation schedules joined with translation job names.
|
||||
@router.get("/automation/translation-schedules", response_model=List[TranslationScheduleItem])
|
||||
async def get_translation_schedules(
|
||||
db: Session = Depends(get_db),
|
||||
_=Depends(has_permission("admin:settings", "READ")),
|
||||
):
|
||||
with belief_scope("get_translation_schedules"):
|
||||
results = (
|
||||
db.query(
|
||||
TranslationSchedule,
|
||||
TranslationJob.name.label("job_name"),
|
||||
)
|
||||
.outerjoin(TranslationJob, TranslationSchedule.job_id == TranslationJob.id)
|
||||
.all()
|
||||
)
|
||||
return [
|
||||
TranslationScheduleItem(
|
||||
schedule_id=ts.id,
|
||||
job_id=ts.job_id,
|
||||
job_name=job_name,
|
||||
cron_expression=ts.cron_expression,
|
||||
timezone=ts.timezone,
|
||||
is_active=ts.is_active,
|
||||
last_run_at=ts.last_run_at,
|
||||
next_run_at=ts.next_run_at,
|
||||
created_by=ts.created_by,
|
||||
created_at=ts.created_at,
|
||||
)
|
||||
for ts, job_name in results
|
||||
]
|
||||
|
||||
|
||||
# #endregion get_translation_schedules
|
||||
|
||||
# #endregion SettingsRouter
|
||||
|
||||
@@ -81,7 +81,7 @@ async def set_schedule(
|
||||
schedule = scheduler.update_schedule(
|
||||
job_id,
|
||||
cron_expression=payload.cron_expression,
|
||||
timezone=payload.timezone,
|
||||
timezone_str=payload.timezone,
|
||||
is_active=payload.is_active,
|
||||
)
|
||||
else:
|
||||
@@ -92,7 +92,7 @@ async def set_schedule(
|
||||
is_active=payload.is_active,
|
||||
)
|
||||
# Register with APScheduler via SchedulerService
|
||||
from ...dependencies import get_scheduler_service
|
||||
from ....dependencies import get_scheduler_service
|
||||
sched_svc = get_scheduler_service()
|
||||
sched_svc.add_translation_job(
|
||||
schedule_id=schedule.id,
|
||||
@@ -133,7 +133,7 @@ async def enable_schedule(
|
||||
try:
|
||||
scheduler = TranslationScheduler(db, config_manager, current_user.username)
|
||||
schedule = scheduler.set_schedule_active(job_id, is_active=True)
|
||||
from ...dependencies import get_scheduler_service
|
||||
from ....dependencies import get_scheduler_service
|
||||
sched_svc = get_scheduler_service()
|
||||
sched_svc.add_translation_job(
|
||||
schedule_id=schedule.id,
|
||||
@@ -164,7 +164,7 @@ async def disable_schedule(
|
||||
try:
|
||||
scheduler = TranslationScheduler(db, config_manager, current_user.username)
|
||||
scheduler.set_schedule_active(job_id, is_active=False)
|
||||
from ...dependencies import get_scheduler_service
|
||||
from ....dependencies import get_scheduler_service
|
||||
sched_svc = get_scheduler_service()
|
||||
sched_svc.remove_translation_job(schedule_id=job_id)
|
||||
return {"status": "disabled", "job_id": job_id}
|
||||
@@ -190,7 +190,7 @@ async def delete_schedule(
|
||||
try:
|
||||
scheduler = TranslationScheduler(db, config_manager, current_user.username)
|
||||
scheduler.delete_schedule(job_id)
|
||||
from ...dependencies import get_scheduler_service
|
||||
from ....dependencies import get_scheduler_service
|
||||
sched_svc = get_scheduler_service()
|
||||
sched_svc.remove_translation_job(schedule_id=job_id)
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user