Skip to content
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
merged 1 commit into from
Dec 14, 2024

Conversation

wintonzheng
Copy link
Contributor

@wintonzheng wintonzheng commented Dec 12, 2024

Important

Send webhooks when tasks or workflow runs are canceled by updating execute_step(), execute_workflow(), and related functions to handle webhook execution.

  • Behavior:
    • Send webhook when task or workflow run is canceled by setting need_call_webhook=True in execute_step() in agent.py and execute_workflow() in service.py.
    • Modify cancel_task() and cancel_workflow_run() in agent_protocol.py to include x_api_key for webhook execution.
  • Functions:
    • Update execute_task_webhook() in agent.py to accept last_step as Step | None.
    • Add execute_workflow_webhook() in service.py to handle webhook execution for workflow runs.
  • Misc:
    • Minor logging adjustments in service.py for webhook execution.

This description was created by Ellipsis for ac4a400. It will automatically update as commits are pushed.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Reviewed everything up to ac4a400 in 25 minutes and 27 seconds

More details
  • Looked at 154 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. skyvern/forge/agent.py:1546
  • Draft comment:
    The change to accept last_step as Step | None in execute_task_webhook is appropriate and consistent with its usage.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The change in execute_task_webhook method to accept last_step as Step | None is appropriate, as it allows for flexibility when the last step might not be available. This change is consistent with the usage in the codebase.
2. skyvern/forge/sdk/workflow/service.py:888
  • Draft comment:
    The change to accept api_key as str | None in execute_workflow_webhook is appropriate and consistent with its usage.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The change in execute_workflow_webhook method to accept api_key as str | None is appropriate, as it allows for cases where the API key might not be provided. This change is consistent with the usage in the codebase.
3. skyvern/forge/sdk/routes/agent_protocol.py:287
  • Draft comment:
    The addition of x_api_key as a header in cancel_task is appropriate for passing API keys for authentication.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The change in cancel_task to include x_api_key as a header is consistent with the need to pass API keys for authentication and is used correctly in the function.
4. skyvern/forge/sdk/routes/agent_protocol.py:308
  • Draft comment:
    The addition of x_api_key as a header in cancel_workflow_run is appropriate for passing API keys for authentication.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The change in cancel_workflow_run to include x_api_key as a header is consistent with the need to pass API keys for authentication and is used correctly in the function.

Workflow ID: wflow_mRaU7xEO2B9PxSqw


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@@ -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)
Copy link
Collaborator

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?

Copy link
Collaborator

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 🤔

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Comment on lines +310 to +317
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question as task

@wintonzheng wintonzheng merged commit 007cf86 into main Dec 14, 2024
2 checks passed
@wintonzheng wintonzheng deleted the shu/send_webhook_when_task.workflow_is_canceled branch December 14, 2024 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants