Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger] Batch consumer: don't flush unless jobs amount is equal or greater than batch size #54600

Open
@ozahorulia

Description

@ozahorulia

Description

When defining a batch consumer with a batch size bigger than current amount of messages in queue, it still flushes the queue no matter what by adding FlushBatchHandlersStamp to the envelope. I need it to wait until the amount of jobs would be greater or equal to my batch size OR flush it every X minutes otherwise. I tried to redeclare flush method like this:

    public function flush(bool $force): void
    {
        if (!$force) {
            // Here I was thinking to add an internal timer of some sort
            return;
        }

        if ($jobs = $this->jobs) {
            $this->jobs = [];
            $this->process($jobs);
        }
    }

But it doesn't really work, because flush() will not be called unless new message in the queue appears.

Then, according to the docs, "... pending batches are flushed when the worker is stopped.", so I tried to add --time-limit to the consumer call. But in this case I'm just getting this error:

The acknowledger was not called by the "..." batch handler

I'm not completely sure whether this is a bug or expected behavior, but it's clear that messenger component is not able to∂ handle batch messages waiting for the needed amount of messages in the queue.

Am I missing something?

Example

Nothing to add here to be honest. Probably it could be additional methods for the BatchHandlerInterface to define some kind of a timeout before force flush or flag if jobs must be flushed if their amount is less than batch size

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions