-
Notifications
You must be signed in to change notification settings - Fork 777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
send webhook when task or workflow run is canceled #1374
Merged
wintonzheng
merged 1 commit into
main
from
shu/send_webhook_when_task.workflow_is_canceled
Dec 14, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -284,6 +284,7 @@ async def get_task( | |
async def cancel_task( | ||
task_id: str, | ||
current_org: Organization = Depends(org_auth_service.get_current_org), | ||
x_api_key: Annotated[str | None, Header()] = None, | ||
) -> None: | ||
analytics.capture("skyvern-oss-agent-task-get") | ||
task_obj = await app.DATABASE.get_task(task_id, organization_id=current_org.organization_id) | ||
|
@@ -292,16 +293,28 @@ async def cancel_task( | |
status_code=status.HTTP_404_NOT_FOUND, | ||
detail=f"Task not found {task_id}", | ||
) | ||
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 | ||
await app.agent.execute_task_webhook(task=task, last_step=latest_step, api_key=x_api_key) | ||
|
||
|
||
@base_router.post("/workflows/runs/{workflow_run_id}/cancel") | ||
@base_router.post("/workflows/runs/{workflow_run_id}/cancel/", include_in_schema=False) | ||
async def cancel_workflow_run( | ||
workflow_run_id: str, | ||
current_org: Organization = Depends(org_auth_service.get_current_org), | ||
x_api_key: Annotated[str | None, Header()] = None, | ||
) -> None: | ||
workflow_run = await app.DATABASE.get_workflow_run(workflow_run_id=workflow_run_id) | ||
if not workflow_run: | ||
raise HTTPException( | ||
status_code=status.HTTP_404_NOT_FOUND, | ||
detail=f"Workflow run not found {workflow_run_id}", | ||
) | ||
await app.WORKFLOW_SERVICE.mark_workflow_run_as_canceled(workflow_run_id) | ||
await app.WORKFLOW_SERVICE.execute_workflow_webhook(workflow_run, api_key=x_api_key) | ||
Comment on lines
+310
to
+317
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same question as task |
||
|
||
|
||
@base_router.post( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we just only send the webhook when task/workflow cancellation is finished? any specific reason why we must send the webhook in the API call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if user call multiple times to the cancle endpoint. he will receive multiple times the webhook without any task/workflow being cancelled 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
users can also cancel tasks that are stuck. our worker won't really send a webhook if we don't send a webhook to them in the API endpoint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it's okay that we send two cancel task webhook.