Skip to content

Graceful Termination Queue Listen while scaling down #521

@mohavee

Description

@mohavee

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions