-
-
Notifications
You must be signed in to change notification settings - Fork 758
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
[BUG] Canceled task goes into retry state #532
Comments
我也碰到了这个问题 我以为就我碰到了呢,我想把任务终止掉 而且设置了重试次数为0, 但是当我cancel task时 这个任务会重新启动,而且原来的task也没有终止掉 最终时跑了2个任务。。。 |
As I know based on explain by code:
When you action
At the Subscriber will receive msg and action
Therefore,
I think it can it is the author's intention. |
why? |
I think the |
if @dxl3811051 wants as your expected, I can update it into my repo. Then you can use it for now. We need to confirm the author to merge to this repo. |
thanks |
@linhbkhn95 how do you move to archive then? i tried cancelling the task but it doesnt work. it says i should use |
We cannot move directly from a normal task to an archive task. It only performs it when num of retry reach >= the limit. If you need it can improve at my repo instead of at this repo. @OAyomide |
I'm running into this issue as well. It would be trivial to write middleware that could check if the context has been cancelled and return an I propose that instead of using Thoughts? |
After more investigation my solution above will not work. Asynq returns context.Cancelled error right away and does not wait for the task to finish or read it's error message. This was also explained above by @linhbkhn95 but I missed it. I think it would be nice if we could have a mechanism to cancel and skip retry via the inspector. |
I don't think we can have a case where any context.Cancelled error pushes a task into archived state here. The potential side effects are just too many. Ideally we want something in the |
As a temporary solution until the library itself solves this issue, I've ended up using this code to cancel tasks: func (t *Tasker) CancelTask(queue, id string) error {
if err := t.inspector.CancelProcessing(id); err != nil {
return err
}
for range 100 {
err := t.inspector.ArchiveTask(queue, id)
if err == nil {
break
}
if errors.Is(err, asynq.ErrTaskNotFound) || errors.Is(err, asynq.ErrQueueNotFound) {
break
}
time.Sleep(time.Millisecond * 100)
}
return nil
} It might not work if you have no retry delay set, so use at your own risk. |
Suppose there is a long running task and it would not success anymore, then the best practice is to just cancel it without any retries to save the worker resources |
Describe the bug
Canceled task goes into retry state, and is consumed again.
If I return a Skip retry error, it is ignored.
To Reproduce
Steps to reproduce the behavior (Code snippets if applicable):
Expected behavior
A canceled task should be archived or completed, we do not want it to be consumed again.
Code sample
Here's the code of my handler (the rest of the setup is standard):
Environment (please complete the following information):
asynq
package: v0.23.0Additional context
When I watch the error in processor.go, handleFailedMessage, the error is "Context canceled", even if I return a "skip retry" error in my task, it is ignored. Naively, I would add "context canceled" to the condition to skip retry, but perhaps I'm missing something ?
The text was updated successfully, but these errors were encountered: