From 3e633c40ddb83314b040a9b92bdf3298d2cbc83c Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Tue, 21 Feb 2023 13:56:34 +0100 Subject: [PATCH] [Messenger] Allow to define batch size when using `BatchHandlerTrait` with `getBatchSize()` --- messenger.rst | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/messenger.rst b/messenger.rst index 05427ac651e..367c0e1951e 100644 --- a/messenger.rst +++ b/messenger.rst @@ -2173,14 +2173,26 @@ provided in order to ease the declaration of these special handlers:: } } - // Optionally, you can redefine the `shouldFlush()` method - // of the trait to define your own batch size + // Optionally, you can either redefine the `shouldFlush()` method + // of the trait to define your own batch size... private function shouldFlush(): bool { return 100 <= \count($this->jobs); } + + // ... or redefine the `getBatchSize()` method if the default + // flush behavior suits your needs + private function getBatchSize(): int + { + return 100; + } } +.. versionadded:: 6.3 + + The :method:`Symfony\\Component\\Messenger\\Handler\\BatchHandlerTrait::getBatchSize` + method was introduced 6.3. + .. note:: When the ``$ack`` argument of ``__invoke()`` is ``null``, the message is