yiisoft / yiisoft/queue

Add a method to clear all messages from a channel

Open
#306 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
61
Forks
31
Avg merge
1d 7h
Merged PRs (30d)
9

Description

Proposed new feature or change

There's no programmatic way to empty a queue. It comes up in three places:

  1. Maintenance - a queue:purge command or an admin button to drop a queue that got flooded with poison pills or jobs that are no longer wanted.
  2. Deployments - clearing a queue during a release when the payload structure changed and old queued jobs would crash on the new code.
  3. Testing - resetting state between runs. Shelling out to redis-cli or rabbitmqctl makes the test suite fragile and awkward to run in containerized CI.

I wouldn't put this on AdapterInterface - that would break every existing implementation and it overlaps with the "not the job of the primary interface" point from #271. A separate opt-in interface fits better:

interface PurgeableInterface
{
    public function purge(): void;
}

Adapters implement it when the backend can do it cheaply (Redis drops the channel keys, AMQP calls queue_purge, the in-memory adapter resets its array). Callers check for it:

if ($adapter instanceof PurgeableInterface) {
    $adapter->purge();
}

Open questions:

  1. Name: purge() (broker vocabulary) or clear()?
  2. Signature: purge(): void on the adapter's current channel (consistent with push/status, which don't take a channel) or purge(string $channel)?

Worth pursuing? Happy to send a PR if you're good with it (core + redis/amqp).

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 by reading AdapterInterface and the existing push/status entry points, then inspect the Redis, AMQP, and in-memory adapters. Resolve the purge-versus-clear name and channel-signature questions; done means the opt-in interface and the proposed adapter implementations support emptying a channel without changing the primary interface.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, rabbitmq, redis
Domain
backend, distributed-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.