You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

36 lines
1.3 KiB

from __future__ import annotations
from sqlalchemy.ext.asyncio import AsyncSession
from app.core.exceptions import FileNotFoundError
from app.repositories.backend_repository import BackendRepository
from app.repositories.file_repository import FileRepository
from app.services.job_service import JobService
class RepairService:
def __init__(self, session: AsyncSession) -> None:
self.session = session
self.file_repository = FileRepository(session)
self.backend_repository = BackendRepository(session)
self.job_service = JobService(session)
async def enqueue_repairs_for_file(self, file_id: str) -> int:
file_entry = await self.file_repository.get_by_id(file_id)
if file_entry is None or file_entry.is_deleted or file_entry.deleted_at is not None:
raise FileNotFoundError()
await self.job_service.enqueue_file_reconcile(file_id)
return 1
async def enqueue_backend_health_checks(self) -> int:
backends = await self.backend_repository.list_enabled()
enqueued = 0
for backend in backends:
await self.job_service.enqueue_backend_health_check(backend.id)
enqueued += 1
return enqueued
async def enqueue_full_reconcile(self) -> int:
await self.job_service.enqueue_full_reconcile()
return 1