Skip to content

Commit

Permalink
Extract method: ::getWorkerCount()
Browse files Browse the repository at this point in the history
  • Loading branch information
jigarius committed Dec 13, 2023
1 parent bba6a4f commit 072d349
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
36 changes: 25 additions & 11 deletions src/Command/ExecCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

// Determine number of workers.
$workers = $input->getOption('drall-workers');

if ($workers > self::WORKER_LIMIT) {
$this->logger->warning('Limiting workers to {count}, which is the maximum.', ['count' => self::WORKER_LIMIT]);
$workers = self::WORKER_LIMIT;
}

if ($workers > 1) {
$this->logger->notice("Using {count} workers.", ['count' => $workers]);
}
$workers = $this->getWorkerCount($input);

// Display commands without executing them.
if ($input->getOption('drall-no-execute')) {
Expand Down Expand Up @@ -227,6 +217,30 @@ protected function getCommand(): RawCommand {
return $command;
}

/**
* Gets the number of workers that should be used.
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* The input.
*
* @return int
* Number of workers to be used.
*/
protected function getWorkerCount(InputInterface $input): int {
$result = $input->getOption('drall-workers');

if ($result > self::WORKER_LIMIT) {
$this->logger->warning('Limiting workers to {count}, which is the maximum.', ['count' => self::WORKER_LIMIT]);
$result = self::WORKER_LIMIT;
}

if ($result > 1) {
$this->logger->notice("Using {count} workers.", ['count' => $result]);
}

return $result;
}

/**
* Get unique placeholder from a command.
*/
Expand Down
2 changes: 1 addition & 1 deletion test/Unit/Command/ExecCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function testWithMixedPlaceholders() {
}

/**
* Drall caps the maximum number of workers.
* Drall caps the maximum number of workers to pre-determined limit.
*/
public function testWorkerLimit() {
$input = [
Expand Down

0 comments on commit 072d349

Please sign in to comment.