Skip to content
Snippets Groups Projects

Resolve "Workflow usage statistics"

Merged Daniel Göbel requested to merge feature/24-workflow-usage-statistics into development
5 files
+ 125
14
Compare changes
  • Side-by-side
  • Inline
Files
5
from typing import Annotated, Any, Awaitable, Callable
from clowmdb.models import Workflow, WorkflowVersion
from fastapi import APIRouter, BackgroundTasks, Depends, File, HTTPException, Query, UploadFile, status
from fastapi import APIRouter, BackgroundTasks, Depends, File, HTTPException, Query, Response, UploadFile, status
from app.api.dependencies import AuthorizationDependency, CurrentUser, CurrentWorkflow, DBSession, HTTPClient, S3Service
from app.api.utils import check_repo, upload_icon
from app.core.config import settings
from app.crud import CRUDWorkflow, CRUDWorkflowVersion
from app.git_repository import build_repository
from app.schemas.workflow import WorkflowIn, WorkflowOut
from app.schemas.workflow import WorkflowIn, WorkflowOut, WorkflowStatistic
from app.schemas.workflow_version import WorkflowVersionFull, WorkflowVersionUpdate
router = APIRouter(prefix="/workflows", tags=["Workflow"])
@@ -72,7 +72,7 @@ async def list_workflows(
rbac_operation = "list_filter"
await authorization(rbac_operation)
workflows: list[Workflow] = await CRUDWorkflow.list(
workflows: list[Workflow] = await CRUDWorkflow.list_workflows(
db,
name_substring=name_substring,
developer_id=developer_id,
@@ -205,6 +205,34 @@ async def get_workflow(
return WorkflowOut.from_db_workflow(workflow, versions)
@router.get("/{wid}/statistics", status_code=status.HTTP_200_OK, summary="Get statistics for a workflow")
async def get_workflow_statistics(
workflow: CurrentWorkflow, db: DBSession, authorization: Authorization, response: Response
) -> list[WorkflowStatistic]:
"""
Get the number of started workflow per day.
\f
Parameters
----------
workflow : clowmdb.models.Workflow
Workflow with given ID. Dependency Injection.
db : sqlalchemy.ext.asyncio.AsyncSession.
Async database session to perform query on. Dependency Injection.
authorization : Callable[[str], Awaitable[Any]]
Async function to ask the auth service for authorization. Dependency Injection.
response : fastapi.Response
Temporal Response object. Dependency Injection.
Returns
-------
statistics : list[app.schema.Workflow.WorkflowStatistic]
"""
await authorization("read")
# Instruct client to cache response for 1 hour
response.headers["Cache-Control"] = "max-age=3600"
return await CRUDWorkflow.statistics(db, workflow.workflow_id)
@router.delete("/{wid}", status_code=status.HTTP_204_NO_CONTENT, summary="Delete a workflow")
async def delete_workflow(
background_tasks: BackgroundTasks,
Loading