Skip to content

Commit

Permalink
Move slack notification into the blt command (#1464)
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish authored Feb 22, 2024
1 parent 11da71c commit b797a6b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 53 deletions.
38 changes: 35 additions & 3 deletions blt/src/Blt/Plugin/Commands/HsCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ class HsCommands extends BltTasks {
*
* @aliases humsci:post-code-update
*/
public function postCodeDeployUpdate() {
public function postCodeDeployUpdate($target_env, $deployed_tag) {
$sites = $this->getConfigValue('multisites');
$parallel_executions = 10;
$parallel_executions = (int) getenv('UPDATE_PARALLEL_PROCESSES') ?: 10;

$site_chunks = array_chunk($sites, ceil(count($sites) / $parallel_executions));
$commands = [];
foreach ($site_chunks as $sites) {
Expand All @@ -50,11 +51,42 @@ public function postCodeDeployUpdate() {
$failed[] = $site;
}
}
unlink(sys_get_temp_dir() . '/update-report.txt');

$this->yell(sprintf('Updated %s sites successfully.', count($success)), 100);

if ($failed) {
$this->yell(sprintf("Update failed for the following sites:\n%s", implode("\n", $failed)), 100, 'red');

if (in_array($target_env, ['prod', 'test'])) {
$count = count($failed);
$this->sendSlackNotification("A new deployment has been made to *$target_env* using *$deployed_tag*.\n\n*$count* sites failed to update.");
}
throw new \Exception('Failed update');
}
unlink(sys_get_temp_dir() . '/update-report.txt');

if (in_array($target_env, ['prod', 'test'])) {
$this->sendSlackNotification("A new deployment has been made to *$target_env* using *$deployed_tag*.");
}
}

/**
* Send out a slack notification.
*
* @param string $message
* Slack message.
*/
protected function sendSlackNotification(string $message) {
$client = new Client();
$client->post(getenv('SLACK_NOTIFICATION_URL'), [
'form_params' => [
'payload' => json_encode([
'username' => 'Acquia Cloud',
'text' => $message,
'icon_emoji' => 'information_source',
]),
],
]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion hooks/common/post-code-deploy/post-code-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ repo_root="/var/www/html/$site.$target_env"
export PATH=$repo_root/vendor/bin:$PATH
cd $repo_root

blt humsci:post-code-deploy
blt humsci:post-code-deploy $target_env $deployed_tag

set +v
2 changes: 1 addition & 1 deletion hooks/common/post-code-update/post-code-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ repo_root="/var/www/html/$site.$target_env"
export PATH=$repo_root/vendor/bin:$PATH
cd $repo_root

blt humsci:post-code-deploy
blt humsci:post-code-deploy $target_env $deployed_tag

set +v
24 changes: 0 additions & 24 deletions hooks/prod/post-code-deploy/slack.sh

This file was deleted.

Empty file.
24 changes: 0 additions & 24 deletions hooks/test/post-code-update/slack.sh

This file was deleted.

0 comments on commit b797a6b

Please sign in to comment.