Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Configuration/Watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Watcher extends AbstractConfiguration
'scenarios',
'api_timeout',
'api_connect_timeout',
'signals_batch_size',
'metrics',
];

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
8 changes: 7 additions & 1 deletion src/Watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
Loading