Skip to content

Commit

Permalink
Limit number of parallel processes
Browse files Browse the repository at this point in the history
  • Loading branch information
iamluc committed Feb 4, 2016
1 parent 4e34e59 commit 9d10184
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/Buse/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

class AbstractCommand extends Command implements ContainerAwareInterface
{
const MAX_PROCESSES = 10;

private $container;

private $groups = [];
Expand Down Expand Up @@ -143,10 +145,14 @@ public function display(array $repositories, array $formatters)

protected function runProcesses(array $repositories, array $processes, array $formatters)
{
$running = 0;
while (count($processes) > 0) {
foreach ($processes as $i => $process) {
if (!$process->isStarted()) {
$process->start();
if ($running < self::MAX_PROCESSES) {
$running++;
$process->start();
}

continue;
}
Expand All @@ -161,6 +167,7 @@ protected function runProcesses(array $repositories, array $processes, array $fo

if (!$process->isRunning()) {
$formatters[$i]->finish($process->getExitCode());
$running--;
unset($processes[$i]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Buse/Command/CloneCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function cloneGroup($group, $repositoriesConfig, $prefix)
$dir = $prefix.$dir;

$repositories[] = $dir;
$formatters[] = new Spinner(sprintf('Cloning %s...', $url), 'Done');
$formatters[] = new Spinner(sprintf('Waiting to clone %s...', $url), 'Done');
$processes[] = $this->getProcess($dir, 'git', ['clone', $url, $dir]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Buse/Command/Fetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$formatters = [];
$processes = [];
foreach ($repositories as $repo) {
$formatters[] = new Spinner(sprintf('fetching %s...', $remote), 'Done');
$formatters[] = new Spinner(sprintf('Waiting to fetch %s...', $remote), 'Done');
$processes[] = $this->getProcess($repo, 'git', $args);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Buse/Command/Pull.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$formatters = [];
$processes = [];
foreach ($repositories as $repo) {
$formatters[] = new Spinner(sprintf('pulling %s...', $ref));
$formatters[] = new Spinner(sprintf('Waiting to pull %s...', $ref));
$processes[] = $this->getProcess($repo, 'git', $args);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Buse/Command/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$formatters = [];
$processes = [];
foreach ($repositories as $repo) {
$formatters[] = new Spinner(sprintf('pushing %s...', $ref));
$formatters[] = new Spinner(sprintf('Waiting to push %s...', $ref));
$processes[] = $this->getProcess($repo, 'git', $args);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Buse/Command/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ protected function displayTags(array $repositories)
protected function createTag(InputInterface $input, array $repositories, $tagName)
{
$args = ['tag'];
$message = 'tagging tag %s...';
$message = 'Waiting to tag %s...';
if ($input->getOption('delete')) {
$args[] = '--delete';
$message = 'deleting tag %s...';
$message = 'Waiting to delete tag %s...';
}
$args[] = $tagName;

Expand Down

0 comments on commit 9d10184

Please sign in to comment.