Skip to content

[Messenger] batch handler and delayed flush #46869

Answered by AdamKatzDev
AdamKatzDev asked this question in Q&A
Discussion options

You must be logged in to vote

We've built an event listener that flushes our handlers with the false flag after every WorkerRunningEvent. Every batch handler in our case has a timer, when flush is called handlers process current batch if enough time has passed or the batch is full.

The event listener is quite a thing in itself, I'll provide the code just in case someone needs something similar.

src/EventSubscriber/Messenger/FlushBatchesOnWorkerEventsListener.php

<?php

declare(strict_types=1);

namespace App\EventSubscriber\Messenger;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Messenger\Event\WorkerMessageReceivedEvent;
use Symfony\Component\Messenger\Event\WorkerRunningEven…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@AdamKatzDev
Comment options

Answer selected by AdamKatzDev
Comment options

You must be logged in to vote
1 reply
@AdamKatzDev
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants