execute_task_webhook uses the latest non canceled step (#4007)
This commit is contained in:
@@ -3138,12 +3138,11 @@ class ForgeAgent:
|
|||||||
await app.ARTIFACT_MANAGER.wait_for_upload_aiotasks([task.task_id])
|
await app.ARTIFACT_MANAGER.wait_for_upload_aiotasks([task.task_id])
|
||||||
|
|
||||||
if need_call_webhook:
|
if need_call_webhook:
|
||||||
await self.execute_task_webhook(task=task, last_step=last_step, api_key=api_key)
|
await self.execute_task_webhook(task=task, api_key=api_key)
|
||||||
|
|
||||||
async def execute_task_webhook(
|
async def execute_task_webhook(
|
||||||
self,
|
self,
|
||||||
task: Task,
|
task: Task,
|
||||||
last_step: Step | None,
|
|
||||||
api_key: str | None,
|
api_key: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
if not api_key:
|
if not api_key:
|
||||||
@@ -3159,6 +3158,7 @@ class ForgeAgent:
|
|||||||
task_id=task.task_id,
|
task_id=task.task_id,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
last_step = await app.DATABASE.get_latest_step(task.task_id, organization_id=task.organization_id)
|
||||||
|
|
||||||
task_response = await self.build_task_response(task=task, last_step=last_step)
|
task_response = await self.build_task_response(task=task, last_step=last_step)
|
||||||
# try to build the new TaskRunResponse for backward compatibility
|
# try to build the new TaskRunResponse for backward compatibility
|
||||||
|
|||||||
@@ -532,6 +532,7 @@ class AgentDB:
|
|||||||
select(StepModel)
|
select(StepModel)
|
||||||
.filter_by(task_id=task_id)
|
.filter_by(task_id=task_id)
|
||||||
.filter_by(organization_id=organization_id)
|
.filter_by(organization_id=organization_id)
|
||||||
|
.filter(StepModel.status != StepStatus.canceled)
|
||||||
.order_by(StepModel.order.desc())
|
.order_by(StepModel.order.desc())
|
||||||
.order_by(StepModel.retry_index.desc())
|
.order_by(StepModel.retry_index.desc())
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1644,10 +1644,8 @@ async def cancel_task(
|
|||||||
detail=f"Task not found {task_id}",
|
detail=f"Task not found {task_id}",
|
||||||
)
|
)
|
||||||
task = await app.agent.update_task(task_obj, status=TaskStatus.canceled)
|
task = await app.agent.update_task(task_obj, status=TaskStatus.canceled)
|
||||||
# get latest step
|
|
||||||
latest_step = await app.DATABASE.get_latest_step(task_id, organization_id=current_org.organization_id)
|
|
||||||
# retry the webhook
|
# retry the webhook
|
||||||
await app.agent.execute_task_webhook(task=task, last_step=latest_step, api_key=x_api_key)
|
await app.agent.execute_task_webhook(task=task, api_key=x_api_key)
|
||||||
|
|
||||||
|
|
||||||
async def _cancel_workflow_run(workflow_run_id: str, organization_id: str, x_api_key: str | None = None) -> None:
|
async def _cancel_workflow_run(workflow_run_id: str, organization_id: str, x_api_key: str | None = None) -> None:
|
||||||
@@ -1778,7 +1776,7 @@ async def retry_webhook(
|
|||||||
return await app.agent.build_task_response(task=task_obj)
|
return await app.agent.build_task_response(task=task_obj)
|
||||||
|
|
||||||
# retry the webhook
|
# retry the webhook
|
||||||
await app.agent.execute_task_webhook(task=task_obj, last_step=latest_step, api_key=x_api_key)
|
await app.agent.execute_task_webhook(task=task_obj, api_key=x_api_key)
|
||||||
|
|
||||||
return await app.agent.build_task_response(task=task_obj, last_step=latest_step)
|
return await app.agent.build_task_response(task=task_obj, last_step=latest_step)
|
||||||
|
|
||||||
|
|||||||
@@ -86,8 +86,7 @@ async def cancel_task_v1(task_id: str, organization_id: str | None = None, api_k
|
|||||||
if not task:
|
if not task:
|
||||||
raise TaskNotFound(task_id=task_id)
|
raise TaskNotFound(task_id=task_id)
|
||||||
task = await app.agent.update_task(task, status=TaskStatus.canceled)
|
task = await app.agent.update_task(task, status=TaskStatus.canceled)
|
||||||
latest_step = await app.DATABASE.get_latest_step(task_id, organization_id=organization_id)
|
await app.agent.execute_task_webhook(task=task, api_key=api_key)
|
||||||
await app.agent.execute_task_webhook(task=task, last_step=latest_step, api_key=api_key)
|
|
||||||
|
|
||||||
|
|
||||||
async def cancel_task_v2(task_id: str, organization_id: str | None = None) -> None:
|
async def cancel_task_v2(task_id: str, organization_id: str | None = None) -> None:
|
||||||
@@ -164,7 +163,7 @@ async def retry_run_webhook(run_id: str, organization_id: str | None = None, api
|
|||||||
raise TaskNotFound(task_id=run_id)
|
raise TaskNotFound(task_id=run_id)
|
||||||
latest_step = await app.DATABASE.get_latest_step(run_id, organization_id=organization_id)
|
latest_step = await app.DATABASE.get_latest_step(run_id, organization_id=organization_id)
|
||||||
if latest_step:
|
if latest_step:
|
||||||
await app.agent.execute_task_webhook(task=task, last_step=latest_step, api_key=api_key)
|
await app.agent.execute_task_webhook(task=task, api_key=api_key)
|
||||||
elif run.task_run_type == RunType.task_v2:
|
elif run.task_run_type == RunType.task_v2:
|
||||||
task_v2 = await app.DATABASE.get_task_v2(run_id, organization_id=organization_id)
|
task_v2 = await app.DATABASE.get_task_v2(run_id, organization_id=organization_id)
|
||||||
if not task_v2:
|
if not task_v2:
|
||||||
|
|||||||
Reference in New Issue
Block a user