-
-
Notifications
You must be signed in to change notification settings - Fork 293
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
Graceful Termination Queue Listen while scaling down #521
Comments
I think that's correct behavior you are describing. How do you run queues? What's in your entry script/cmd? |
The workers are running as a Kubernetes Deployment, scaled using HPA (Horizontal Pod Autoscaler). The component: 'components' => [
'queueService' => [
'class' => yii\queue\amqp_interop\Queue::class,
'vhost' => '',
'host' => 'rabbitmq',
'port' => 5672,
'user' => '',
'password' => '',
'exchangeName' => 'event_sync_exchange',
'queueName' => 'event_sync_queue',
'driver' => yii\queue\amqp_interop\Queue::ENQUEUE_AMQP_LIB,
]
] The command and args for the container are:
During downscaling, even with a properly configured EDITED: added component, changed the args. |
What's rabbit/leaflets? |
Ive updated the original comment. |
OK. That looks valid and is likely a bug. Can't dig into it right now myself though :( |
This is a known issue for long handlers when running in K8S. It can also occur when using a RabbitMQ cluster and the accompanying HAProxy. The thing is that you need to tell the server that your connection is still alive. You can use the
However, this may still not solve the connection failure problem for K8S and HAProxy, and your handler may fail with an error or lose connection with the server and not reconnect (for example, if the timeout on Ingress k8s and HAProxy are different). In this case, the frame calculation based on the set heartbeat seconds will not fall within this interval. You can additionally add a eg protected function setupBroker(): void
{
if ($this->setupBrokerDone) {
return;
}
static $reconnectAttempt = 0;
try {
parent::setupBroker();
} catch (Throwable $e) {
if ($reconnectAttempt < $this->retries) {
$this->close();
$reconnectAttempt++;
if ($this->retryInterval > 0) {
usleep($this->retryInterval);
}
$this->open();
$this->setupBroker();
} else {
throw $e;
}
}
} |
Hello,
We are running queue workers in a Kubernetes environment where pods are short-lived and can be interrupted at any time. Currently, the yii\queue\cli\Queue::listen() method continuously listens for new messages until it receives a termination signal (SIGTERM, SIGINT, or SIGHUP). Found related https://github.com/yiisoft/yii2-queue/issues/399
When we push a long-running job to the queue and send a termination signal (e.g., Ctrl+C), the worker behaves correctly by finishing the current job before stopping. However, after the job is processed, the listen() method hangs. Once a new message is pushed to the queue, the process stops immediately.
Expected Behavior for Graceful Termination when scaling down workers:
Termination signal + empty queue → The worker should stop immediately.
Termination signal during job processing → The worker should complete the current job and stop without continuing to listen for new messages.
Is there a way to achieve this behavior natively in Yii2 Queue?
The text was updated successfully, but these errors were encountered: