feat(scada): add calibrated monitoring and incident recovery
This commit is contained in:
@@ -7,6 +7,7 @@ from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends, Header, HTTPException, Query, status
|
||||
from psycopg import AsyncConnection
|
||||
from app.auth.metadata_dependencies import get_metadata_repository
|
||||
|
||||
from app.auth.permissions import (
|
||||
OPERATIONAL_TASK_EXECUTE,
|
||||
@@ -22,6 +23,7 @@ from app.auth.project_dependencies import (
|
||||
ProjectContext,
|
||||
get_project_context,
|
||||
get_project_pg_connection,
|
||||
get_project_timescale_connection,
|
||||
)
|
||||
from app.domain.domain_errors import DomainError
|
||||
from app.domain.schemas.workbench_runtime import WorkbenchDateTime
|
||||
@@ -90,6 +92,31 @@ from app.services.operational_tasks import OperationalTaskService
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post("/operational-tasks/recovery/reconcile")
|
||||
async def reconcile_task_recoveries(
|
||||
command: RecoverExpiredLeasesCommand,
|
||||
ctx: ProjectContext = Depends(require_permission(OPERATIONAL_TASK_EXECUTE)),
|
||||
conn: AsyncConnection = Depends(get_project_pg_connection),
|
||||
timescale=Depends(get_project_timescale_connection),
|
||||
metadata=Depends(get_metadata_repository),
|
||||
) -> dict[str, int]:
|
||||
from app.domain.schemas.project_settings import ProjectSettings
|
||||
from app.services.operational_recovery import reconcile_recoveries
|
||||
|
||||
if SCADA_VIEW not in permissions_for_context(ctx):
|
||||
raise HTTPException(403, "恢复监测需要 SCADA 查看权限")
|
||||
project = await metadata.get_project_by_id(ctx.project_id)
|
||||
if project is None:
|
||||
raise HTTPException(404, "当前项目不存在")
|
||||
try:
|
||||
resumed = await reconcile_recoveries(_service(ctx, conn), timescale,
|
||||
ProjectSettings.model_validate(project.settings or {}), limit=command.limit,
|
||||
created_from=command.task_created_from)
|
||||
return {"resumed": resumed}
|
||||
except DomainError as exc:
|
||||
_raise_domain(exc)
|
||||
|
||||
|
||||
def _service(ctx: ProjectContext, conn: AsyncConnection) -> OperationalTaskService:
|
||||
return OperationalTaskService(
|
||||
OperationalTaskRepository(conn, ctx.project_id),
|
||||
|
||||
Reference in New Issue
Block a user