2026-06-12 14:55:30 +05:30
|
|
|
from loguru import logger
|
|
|
|
|
from pipecat.utils.run_context import set_current_run_id
|
|
|
|
|
|
|
|
|
|
from api.services.workflow_run_billing import (
|
|
|
|
|
report_completed_workflow_run_platform_usage,
|
|
|
|
|
)
|
|
|
|
|
from api.tasks.run_integrations import run_integrations_post_workflow_run
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def process_workflow_completion(
|
|
|
|
|
_ctx,
|
|
|
|
|
workflow_run_id: int,
|
|
|
|
|
):
|
2026-07-03 20:01:52 +05:30
|
|
|
"""Process workflow completion: run integrations and report billing.
|
2026-06-12 14:55:30 +05:30
|
|
|
|
2026-07-03 20:01:52 +05:30
|
|
|
Recording/transcript uploads happen in the pipeline process itself
|
|
|
|
|
(api/services/workflow_run_artifacts.py) before this job is enqueued,
|
2026-07-07 18:38:29 +05:30
|
|
|
so this task needs no shared filesystem with the web tier.
|
2026-06-12 14:55:30 +05:30
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
_ctx: ARQ context (unused)
|
|
|
|
|
workflow_run_id: The workflow run ID
|
|
|
|
|
"""
|
|
|
|
|
run_id = str(workflow_run_id)
|
|
|
|
|
set_current_run_id(run_id)
|
|
|
|
|
|
|
|
|
|
logger.info(f"Processing workflow completion for run {workflow_run_id}")
|
|
|
|
|
|
2026-07-03 20:01:52 +05:30
|
|
|
# Run integrations including QA analysis (after uploads are complete)
|
2026-06-12 14:55:30 +05:30
|
|
|
try:
|
|
|
|
|
await run_integrations_post_workflow_run(_ctx, workflow_run_id)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error(f"Error running integrations for workflow {workflow_run_id}: {e}")
|
|
|
|
|
|
2026-07-03 20:01:52 +05:30
|
|
|
# Notify MPS after completion. MPS owns credit accounting.
|
2026-06-12 14:55:30 +05:30
|
|
|
try:
|
|
|
|
|
await report_completed_workflow_run_platform_usage(workflow_run_id)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error(
|
|
|
|
|
f"Error reporting platform usage for workflow {workflow_run_id}: {e}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
logger.info(f"Completed workflow completion processing for run {workflow_run_id}")
|