mirror of
https://github.com/hibiken/asynq.git
synced 2026-04-25 23:15:51 +03:00
[GH-ISSUE #968] [FEATURE REQUEST] Allow cancelling task without retrying it #2492
Labels
No labels
CLI
bug
designing
documentation
duplicate
enhancement
good first issue
good first issue
help wanted
idea
invalid
investigate
needs-more-info
performance
pr-welcome
pull-request
question
wontfix
work in progress
work in progress
work-around-available
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/asynq#2492
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @faleksic on GitHub (Nov 13, 2024).
Original GitHub issue: https://github.com/hibiken/asynq/issues/968
Originally assigned to: @hibiken, @kamikazechaser on GitHub.
I want to cancel a task without asynq retrying it. I've tried to return
asynq.SkipRetryerror from the handler when context is canceled, but currently Asynq processor will ignore it and pass context errorctx.Err()to thehandleFailedMessagefunction and my error is ignored.I wish there is a way to call
inspector.CancelProcessing(taskID)and skip retrying that specific task. I am trying to implement a feature where a client can give up on running some task and simply cancel it.One idea to bypass this issue is to set
MaxRetryto 0 and that way it wouldn't be retried, but then the task wouldn't be retried in any other case. How I currently bypassed this issue is that keep my own version ofCancellationsand before running the task I create a different context instead of passing the one given to me by Asynq. That way, I am able to handle the cancel event and returnasynq.SkipRetryto not retry it again. Asynq is not aware that the task is canceled@kamikazechaser commented on GitHub (Nov 14, 2024):
This would be a good feature to have. One way is to handle the
context.Cancellederror case and archive the task. The problem is that would be a breaking change because most of the users are used to the fact that any job that has its context cancelled will be retried (current behavior).We could add an option of
archiveOnCancel (bool)to the server which would then archive the task upon context cancellation or if false, retry it (default).An extra good to have feature would also be to access the
Cancellationsmap directly from the client so that you don't have to cancel through Redis pub/sub which is unreliable.Also btw, in theory, you could register a custom error handler and archive the task with the inspector to achieve the same effect. Maybe i'll test it and document it in the wiki.
Related:
@kamikazechaser commented on GitHub (Nov 14, 2024):
Could you try something like this and pass it to the server Config ErrorHandler and report back.
@faleksic commented on GitHub (Nov 14, 2024):
Just tried it, unfortunately it doesn't work. I get the following error
cannot archive task in active state. use CancelProcessing instead.