mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-13 08:15:21 +02:00
fix: call_id and stream_id for vobiz pipeline, add workflow run state (#78)
* fix: add workflow run state for pipeline * fix: call and stream id for vobiz pipeline
This commit is contained in:
parent
4640f69f9b
commit
c99bd29ef1
10 changed files with 139 additions and 14 deletions
|
|
@ -14,6 +14,7 @@ from starlette.responses import HTMLResponse
|
|||
|
||||
from api.db import db_client
|
||||
from api.db.models import UserModel
|
||||
from api.enums import WorkflowRunState
|
||||
from api.services.auth.depends import get_user
|
||||
from api.services.campaign.call_dispatcher import campaign_call_dispatcher
|
||||
from api.services.campaign.campaign_event_publisher import get_campaign_event_publisher
|
||||
|
|
@ -228,6 +229,14 @@ async def websocket_endpoint(
|
|||
await websocket.close(code=4404, reason="Workflow not found")
|
||||
return
|
||||
|
||||
# Check workflow run state - only allow 'initialized' state
|
||||
if workflow_run.state != WorkflowRunState.INITIALIZED.value:
|
||||
logger.warning(
|
||||
f"Workflow run {workflow_run_id} not in initialized state: {workflow_run.state}"
|
||||
)
|
||||
await websocket.close(code=4409, reason="Workflow run not available for connection")
|
||||
return
|
||||
|
||||
# Extract provider type from workflow run context
|
||||
provider_type = None
|
||||
if workflow_run.gathered_context:
|
||||
|
|
@ -256,6 +265,16 @@ async def websocket_endpoint(
|
|||
await websocket.close(code=4400, reason="Provider mismatch")
|
||||
return
|
||||
|
||||
# Set workflow run state to 'running' before starting the pipeline
|
||||
await db_client.update_workflow_run(
|
||||
run_id=workflow_run_id,
|
||||
state=WorkflowRunState.RUNNING.value
|
||||
)
|
||||
|
||||
logger.info(
|
||||
f"[run {workflow_run_id}] Set workflow run state to 'running' for {provider_type} provider"
|
||||
)
|
||||
|
||||
# Delegate to provider-specific handler
|
||||
await provider.handle_websocket(
|
||||
websocket, workflow_id, user_id, workflow_run_id
|
||||
|
|
@ -362,7 +381,11 @@ async def _process_status_update(
|
|||
await campaign_call_dispatcher.release_call_slot(workflow_run_id)
|
||||
|
||||
# Mark workflow run as completed
|
||||
await db_client.update_workflow_run(run_id=workflow_run_id, is_completed=True)
|
||||
await db_client.update_workflow_run(
|
||||
run_id=workflow_run_id,
|
||||
is_completed=True,
|
||||
state=WorkflowRunState.COMPLETED.value
|
||||
)
|
||||
|
||||
elif status.status in ["failed", "busy", "no-answer", "canceled"]:
|
||||
logger.warning(
|
||||
|
|
@ -396,6 +419,7 @@ async def _process_status_update(
|
|||
await db_client.update_workflow_run(
|
||||
run_id=workflow_run_id,
|
||||
is_completed=True,
|
||||
state=WorkflowRunState.COMPLETED.value,
|
||||
gathered_context={"call_tags": call_tags},
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue