Skip to content

Commit

Permalink
[DX] Inline PARALLEL_SYSTEM_ERROR_COUNT_LIMIT option to keep user sco…
Browse files Browse the repository at this point in the history
…pe outside internal system (#1818)
  • Loading branch information
TomasVotruba committed Feb 15, 2022
1 parent d670c93 commit 9fe4426
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
1 change: 0 additions & 1 deletion config/parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
$parameters->set(Option::PARALLEL_MAX_NUMBER_OF_PROCESSES, 16);
$parameters->set(Option::PARALLEL_JOB_SIZE, 20);
$parameters->set(Option::PARALLEL_TIMEOUT_IN_SECONDS, 120);
$parameters->set(Option::PARALLEL_SYSTEM_ERROR_COUNT_LIMIT, 20);

// FQN class importing
$parameters->set(Option::AUTO_IMPORT_NAMES, false);
Expand Down
15 changes: 8 additions & 7 deletions packages/Parallel/Application/ParallelFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
*/
final class ParallelFileProcessor
{
/**
* @var int
*/
private const SYSTEM_ERROR_LIMIT = 50;

private ProcessPool|null $processPool = null;

public function __construct(
Expand Down Expand Up @@ -125,9 +130,6 @@ public function process(
};

$timeoutInSeconds = $this->parameterProvider->provideIntParameter(Option::PARALLEL_TIMEOUT_IN_SECONDS);
$systemErrorCountLimit = $this->parameterProvider->provideIntParameter(
Option::PARALLEL_SYSTEM_ERROR_COUNT_LIMIT
);

for ($i = 0; $i < $numberOfProcesses; ++$i) {
// nothing else to process, stop now
Expand Down Expand Up @@ -157,8 +159,7 @@ function (array $json) use (
$postFileCallback,
&$systemErrorsCount,
&$reachedInternalErrorsCountLimit,
$processIdentifier,
$systemErrorCountLimit
$processIdentifier
): void {
// decode arrays to objects
foreach ($json[Bridge::SYSTEM_ERRORS] as $jsonError) {
Expand All @@ -177,7 +178,7 @@ function (array $json) use (
$postFileCallback($json[Bridge::FILES_COUNT]);

$systemErrorsCount += $json[Bridge::SYSTEM_ERRORS_COUNT];
if ($systemErrorsCount >= $systemErrorCountLimit) {
if ($systemErrorsCount >= self::SYSTEM_ERROR_LIMIT) {
$reachedInternalErrorsCountLimit = true;
$this->processPool->quitAll();
}
Expand Down Expand Up @@ -220,7 +221,7 @@ function ($exitCode, string $stdErr) use (&$systemErrors, $processIdentifier): v
if ($reachedSystemErrorsCountLimit) {
$systemErrors[] = new SystemError(sprintf(
'Reached system errors count limit of %d, exiting...',
$systemErrorCountLimit
self::SYSTEM_ERROR_LIMIT
));
}

Expand Down
5 changes: 0 additions & 5 deletions src/Configuration/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,6 @@ final class Option
*/
public const PARALLEL_TIMEOUT_IN_SECONDS = 'parallel-timeout-in-seconds';

/**
* @var string
*/
public const PARALLEL_SYSTEM_ERROR_COUNT_LIMIT = 'parallel-system-error-count-limit';

/**
* @var string
*/
Expand Down

0 comments on commit 9fe4426

Please sign in to comment.