| 1 | from loguru import logger |
| 2 | |
| 3 | from app.connectors.shuffle.schema.integrations import ExecuteWorkflowRequest |
| 4 | from app.connectors.shuffle.schema.integrations import IntegrationRequest |
| 5 | from app.connectors.shuffle.utils.universal import send_post_request |
| 6 | |
| 7 | |
| 8 | async def execute_integration(request: IntegrationRequest) -> dict: |
| 9 | """ |
| 10 | Execute a workflow. |
| 11 | |
| 12 | Args: |
| 13 | request (IntegrationRequest): The request object containing the workflow ID. |
| 14 | |
| 15 | Returns: |
| 16 | dict: The response containing the execution ID. |
| 17 | """ |
| 18 | logger.info(f"Executing integration: {request}") |
| 19 | response = await send_post_request("/api/v1/apps/categories/run", request.model_dump()) |
| 20 | logger.info(f"Response: {response}") |
| 21 | return response |
| 22 | |
| 23 | |
| 24 | async def execute_workflow(request: ExecuteWorkflowRequest) -> dict: |
| 25 | """ |
| 26 | Execute a workflow. |
| 27 | |
| 28 | Args: |
| 29 | request (IntegrationRequest): The request object containing the workflow ID. |
| 30 | |
| 31 | Returns: |
| 32 | dict: The response containing the execution ID. |
| 33 | """ |
| 34 | logger.info(f"Executing workflow: {request.model_dump()}") |
| 35 | try: |
| 36 | response = await send_post_request(f"/api/v1/workflows/{request.workflow_id}/execute", request.model_dump()) |
| 37 | logger.info(f"Response: {response}") |
| 38 | return response |
| 39 | except Exception as e: |
| 40 | logger.error(f"Error executing workflow: {e}") |
| 41 | return {"error": str(e)} |