Skip to content
Snippets Groups Projects

Resolve "Workflow usage statistics"

Merged Daniel Göbel requested to merge feature/24-workflow-usage-statistics into development
4 files
+ 74
12
Compare changes
  • Side-by-side
  • Inline
Files
4
from typing import Annotated, Any, Awaitable, Callable
from typing import Annotated, Any, Awaitable, Callable
from clowmdb.models import Workflow, WorkflowVersion
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.dependencies import AuthorizationDependency, CurrentUser, CurrentWorkflow, DBSession, HTTPClient, S3Service
from app.api.utils import check_repo, upload_icon
from app.api.utils import check_repo, upload_icon
from app.core.config import settings
from app.core.config import settings
from app.crud import CRUDWorkflow, CRUDWorkflowVersion
from app.crud import CRUDWorkflow, CRUDWorkflowVersion
from app.git_repository import build_repository
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
from app.schemas.workflow_version import WorkflowVersionFull, WorkflowVersionUpdate
router = APIRouter(prefix="/workflows", tags=["Workflow"])
router = APIRouter(prefix="/workflows", tags=["Workflow"])
@@ -72,7 +72,7 @@ async def list_workflows(
@@ -72,7 +72,7 @@ async def list_workflows(
rbac_operation = "list_filter"
rbac_operation = "list_filter"
await authorization(rbac_operation)
await authorization(rbac_operation)
workflows: list[Workflow] = await CRUDWorkflow.list(
workflows: list[Workflow] = await CRUDWorkflow.list_workflows(
db,
db,
name_substring=name_substring,
name_substring=name_substring,
developer_id=developer_id,
developer_id=developer_id,
@@ -205,6 +205,34 @@ async def get_workflow(
@@ -205,6 +205,34 @@ async def get_workflow(
return WorkflowOut.from_db_workflow(workflow, versions)
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")
@router.delete("/{wid}", status_code=status.HTTP_204_NO_CONTENT, summary="Delete a workflow")
async def delete_workflow(
async def delete_workflow(
background_tasks: BackgroundTasks,
background_tasks: BackgroundTasks,
Loading