-
Notifications
You must be signed in to change notification settings - Fork 326
Description
Problem Summary
In our hatchet usage, we rely on scheduled runs + bulk deleting as a means of implementing "dedupe+debounce" workflows. For example, we have a chat product that schedules a Hatchet workflow 15 minutes in the future keyed on a user id. If the user engages with chat again, we'll use bulk_delete_scheduled to delete (cancel) scheduled workflows keyed on that user id via additional_metadata and reschedule for 15 minutes in the future.
When we call bulk_delete_scheduled with this user id in additional_metadata and no matching workflow IDs are found, the engine returns a 400 error with message Provide scheduledWorkflowRunIds or filter.
link
if len(ids) == 0 {
return gen.WorkflowScheduledBulkDelete400JSONResponse(apierrors.NewAPIErrors("Provide scheduledWorkflowRunIds or filter.")), nil
}
Potential Solutions
There are a few solutions that come to mind, and I'm open to hearing the maintainers' feedback.
- At minimum, the error message is a bit misleading. It seems to indicate a malformed request payload (no
scheduledWorkflowRunIdsor filter) but is actually a runtime condition. - Rather than a 400, this condition could actually result in a 200 response, that is, "You wanted to delete something that doesn't exist, and it doesn't exist, so voila". This could be coupled with a
deleted_idsresponse payload for clients to validate their own behavior. - Perhaps there's a request level flag
tolerate_missing_idswhich allows a client to explicitly opt-in to this behavior.
It's worth noting that the API technically does offer a pathway here to
- List scheduled workflows based on filter
- Cancel based on ID if filter match
This is also reasonable, but could be subject to race conditions (net of other client application-level changes) in a concurrent execution environment where a separate thread creates workflows in between steps 1 and 2.
My personal lean is towards option 2 (don't treat this as a 400 error), although not too strongly held.
Happy to hear the maintainers' thoughts, and should be able to contribute a PR based on feedback.