yiisoft / yiisoft/yii2-queue

Graceful Termination Queue Listen while scaling down

Open
#521 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type:bug
Dominant language
PHP
Stars
1.1k
Forks
285
Avg merge
5d 3h
Merged PRs (30d)
2

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with yii\queue\cli\Queue::listen() and the related issue #399. Reproduce the signal behavior with a long-running job, then an empty queue, and verify how SIGTERM, SIGINT, and SIGHUP are handled. Done means a worker finishes its current job after a termination signal and exits without waiting for another message.

Written by the indexing model from the issue text.

Assessment

Tech stack
kubernetes, php
Domain
backend, devops, distributed-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.