mirror of
https://github.com/hibiken/asynq.git
synced 2026-04-26 07:25:56 +03:00
[GH-ISSUE #710] Question: A way to gracefully shutdown server after single task execution #2370
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#2370
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 @romanilchyshyn on GitHub (Jul 30, 2023).
Original GitHub issue: https://github.com/hibiken/asynq/issues/710
I want to run
asynq.Server-s on top of pool of machines (vm-s, containers whatever). Each machine runs single server withConcurrency = 1. Once a task is successfully executed, I want to call Shutdown() on the server to stop it from processing further tasks. (In general I want to terminate machine and start new "clean" machine from pool manager).However, I have encountered an issue where I cannot simply signal the server to shut down from the task handler. If I proceed with such a shutdown, the handleSucceededMessage(..) will not be called, and the task will remain in the queue.
So, is there any way to implement such behavior?
@kamikazechaser commented on GitHub (Jul 31, 2023):
Are you setting
Config.ShutdownTimeoutto be atleast ~ time taken to execute the task? You will also need to configure your vm/container orchestrator e.g. Docker Compose not to send a SIGKILL instead set a timeout also on that. That is the safest graceful shutdown approach I can think of.@romanilchyshyn commented on GitHub (Jul 31, 2023):
Thanks for the response. But I afraid timing out is not what I'm looking for.
I prob explained it badly. My aim is:
Shutdownbefore start processing next task from redisDon't care about how it orchestrated from the outside.
@kamikazechaser commented on GitHub (Aug 1, 2023):
I see. Even if you were to set a concurrency of 1 on the asynq server, I don't see any guarantee that the next task won't be dequeued before it is shutdown unless you do some complex signal processing.
Though if you want such a setup why not use a simple RPUSH to queue and LPOP by a custom executor. That way you will have a lot of control.
@voidshard commented on GitHub (Oct 14, 2023):
I have another question on graceful shutdown that I think is related to this; The server has a Stop() and a Shutdown(), from reading the comments Stop() prevents the server from picking up more tasks and Shutdown() well .. shutsdown. In theory one can call Stop() on a server, then wait until that server has finished processing all it's tasks, then call Shutdown().
Looking at the inspector I can see a Servers() call which returns all servers, and serverinfos include an ID. But I can't see how I can get the ID of the server I called Stop() on ..?
So in practice, I'm unclear how I would check that the server I've just called Stop() on is actually ready for Shutdown(). I mean, sure I could set some kind of max task time and wait that long before shutdown .. but that seems a little weird.
I'd like to request:
.. Happy to add myself if you want.
My apologies if there is a way to do this currently and I haven't found it!
@kamikazechaser commented on GitHub (Oct 19, 2023):
@voidshard Moved your question to a new issue.