Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chunk parallel processes better and fixup for update sites loop #16

Merged
merged 2 commits into from
Mar 7, 2024
Merged
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
14 changes: 12 additions & 2 deletions src/Blt/Plugin/Commands/SwsCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,16 @@ public function postCodeDeployUpdate($target_env, $deployed_tag, $options = ['no
$sites = $this->getConfigValue('multisites');
$parallel_executions = (int) getenv('UPDATE_PARALLEL_PROCESSES') ?: 10;

$site_chunks = array_chunk($sites, ceil(count($sites) / $parallel_executions));
$i = 0;
while ($sites) {
$site = array_splice($sites, 0, 1);
$site_chunks[$i][] = reset($site);
$i++;
if ($i >= $parallel_executions) {
$i = 0;
}
}

$commands = [];
foreach ($site_chunks as $sites) {
$command = $this->blt()
Expand All @@ -398,6 +407,7 @@ public function postCodeDeployUpdate($target_env, $deployed_tag, $options = ['no
}
$commands[] = $command->getCommand();
}

file_put_contents(sys_get_temp_dir() . '/success-report.txt', '');
file_put_contents(sys_get_temp_dir() . '/failed-report.txt', '');

Expand Down Expand Up @@ -468,7 +478,7 @@ public function updateSites($sites, $options = ['partial-config-import' => FALSE

if ($task->run()->wasSuccessful()) {
file_put_contents(sys_get_temp_dir() . '/success-report.txt', $site_name . PHP_EOL, FILE_APPEND);
return;
continue;
}

file_put_contents(sys_get_temp_dir() . '/failed-report.txt', $site_name . PHP_EOL, FILE_APPEND);
Expand Down