mirror of
https://github.com/hibiken/asynq.git
synced 2026-04-25 23:15:51 +03:00
[GH-ISSUE #396] [QUESTION] Resuming tasks on worker restart #2201
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#2201
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 @hibiken on GitHub (Feb 4, 2022).
Original GitHub issue: https://github.com/hibiken/asynq/issues/396
Our use case is as follows:
Here's a mock code:
Now this is mock code, but basically we retrieve the task ids and reprocess them. The handler receives the reprocessed task but does not update the state to completed afterwards. I tried to manually cancel the task by using
inspector.CancelProcessingbut it doesn't work.Any idea how can I resume a task when the worker server restarts?
Originally posted by @svedova in https://github.com/hibiken/asynq/issues/334#issuecomment-1029913693
@hibiken commented on GitHub (Feb 4, 2022):
@svedova Thank you for commenting with a question (I moved to a new issue since it's slightly different from the original issue).
Where are you getting this
staleTaskIds? Is this a channel or a slice?@svedova commented on GitHub (Feb 7, 2022):
TLDR;
staleTaskIdsare populated by looking at the filesystem. It's a slice of string. We store the task id in the filesytem each time a job is processed and delete them when the job id is processed. When the server restarts, we check the filesystem and if there is anything it means that the task was incomplete and the server crashed while processing the task.=====
Longer version:
@hibiken so this is our use case at Stormkit:
The is the code we use to this operation:
For some reason, the next time the task is picked up (in case server restarts), the task is processed but it's not moved to the completed tab. We use the same task id as we assign a custom id to the task.
@hibiken commented on GitHub (Feb 8, 2022):
@svedova Thanks for providing more detailed info.
You don't have to do this yourself, let the library handle this.
If a worker server crashed and left tasks in active state (i.e. stale/orphaned tasks), it'll be recovered automatically by another server listening to the same queue (this another server could be a restarted process).
So this code is not necessary:
Current implementation (v0.21.0) will recover an orphaned task once its deadline has exceeded (FYI: we have an open issue to improve this #334 by making the recovery quicker). If you want these tasks to be recovered quickly, a recommendation is to specify an appropriate timeout. For example, if your task should be handled within 1m, then you'd specify that via
Timeoutoption.With this, if a server crashes while handling this task, the task's deadline will reach within the next 1m and another server listening to the same queue can recover this task (by moving it from the active state to retry state).
Let me know if you have more questions! I'm happy to assist :)
@svedova commented on GitHub (Feb 8, 2022):
@hibiken thanks a lot for the answer! I guess I'll use it that way but it would be very nice to have the ability to pick it up immediately. Our timeout is 10 minutes and if the server crashes during the first minute the user will have to wait approximately 10 minutes for the task to be picked up. So I guess this becomes a feature request :)
@hibiken commented on GitHub (Feb 9, 2022):
Totally agree with your concern. I'm actively working this right now and it'll be part of the next version.
Please feel free to subscribe to #334, so that you'll be notified when that issue is closed.
Duplicate of #334.