From c8a0232a42ef7d53c410a7e72386d8edcd8417a2 Mon Sep 17 00:00:00 2001 From: jdv Date: Tue, 2 Jun 2026 11:10:15 +0200 Subject: [PATCH] batching signals push by 50 to avoid exeeding request length --- src/Configuration/Watcher.php | 10 ++++++++++ src/Constants.php | 4 ++++ src/Watcher.php | 8 +++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Configuration/Watcher.php b/src/Configuration/Watcher.php index 923d866..dcc63d6 100644 --- a/src/Configuration/Watcher.php +++ b/src/Configuration/Watcher.php @@ -33,6 +33,7 @@ class Watcher extends AbstractConfiguration 'scenarios', 'api_timeout', 'api_connect_timeout', + 'signals_batch_size', 'metrics', ]; @@ -108,6 +109,15 @@ public function getConfigTreeBuilder(): TreeBuilder ->end() ->integerNode('api_timeout')->defaultValue(Constants::API_TIMEOUT)->end() ->integerNode('api_connect_timeout')->defaultValue(Constants::API_CONNECT_TIMEOUT)->end() + ->integerNode('signals_batch_size') + ->defaultValue(Constants::SIGNALS_BATCH_SIZE) + ->validate() + ->ifTrue(function (int $value) { + return $value < 1; + }) + ->thenInvalid('Invalid signals batch size. Must be greater than 0') + ->end() + ->end() ->end() ; $this->addMetricsNodes($rootNode); diff --git a/src/Constants.php b/src/Constants.php index b15eae4..05f7ddb 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -62,6 +62,10 @@ class Constants extends CommonConstants * @var int The number of register retry attempts in case of 500 */ public const REGISTER_RETRY = 1; + /** + * @var int The default maximum number of signals per push request + */ + public const SIGNALS_BATCH_SIZE = 50; /** * @var string The signals push endpoint */ diff --git a/src/Watcher.php b/src/Watcher.php index a1b799c..06e82fa 100644 --- a/src/Watcher.php +++ b/src/Watcher.php @@ -249,8 +249,14 @@ public function getStreamDecisions(): array public function pushSignals(array $signals): array { $indexedSignals = array_values($signals); + $batchSize = $this->getConfig('signals_batch_size') ?? Constants::SIGNALS_BATCH_SIZE; + $chunks = array_chunk($indexedSignals, $batchSize); + $result = []; + foreach ($chunks as $chunk) { + $result = $this->manageRequest('POST', Constants::SIGNALS_ENDPOINT, $chunk); + } - return $this->manageRequest('POST', Constants::SIGNALS_ENDPOINT, $indexedSignals); + return $result; } /**