-
Notifications
You must be signed in to change notification settings - Fork 3
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
Move slack notification into the blt command #1464
Changes from 2 commits
bfa5244
7cdb5ad
372fb87
986228d
026a5b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,16 +17,19 @@ class HsCommands extends BltTasks { | |
|
||
use HsCommandTrait; | ||
|
||
const UPDATE_PARALLEL_PROCESSES = 'UPDATE_PARALLEL_PROCESSES'; | ||
|
||
/** | ||
* After code deployed, update all sites on the stack. | ||
* | ||
* @command humsci:post-code-deploy | ||
* | ||
* @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(self::UPDATE_PARALLEL_PROCESSES) ?: 10; | ||
|
||
$site_chunks = array_chunk($sites, ceil(count($sites) / $parallel_executions)); | ||
$commands = []; | ||
foreach ($site_chunks as $sites) { | ||
|
@@ -50,11 +53,41 @@ 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 (EnvironmentDetector::isAhStageEnv() || EnvironmentDetector::isAhProdEnv()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason you're using these instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not at all. I didn't really think about it. lol |
||
$this->sendSlackNotification("A new deployment has been made to *$target_env* using *$deployed_tag*. At least one site failed updating."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not include the failed sites? Would the message be too long if too many sites failed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I was kinda on the fence about it. I figured it might be less noise in Slack. Maybe we can use the number of sites that failed? then it's still short message There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooh I like that idea. A count would be useful without creating too much noise. |
||
} | ||
throw new \Exception('Failed update'); | ||
} | ||
unlink(sys_get_temp_dir() . '/update-report.txt'); | ||
|
||
if (EnvironmentDetector::isAhStageEnv() || EnvironmentDetector::isAhProdEnv()) { | ||
$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'), [ | ||
pookmish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'form_params' => [ | ||
'payload' => json_encode([ | ||
'username' => 'Acquia Cloud', | ||
'text' => $message, | ||
'icon_emoji' => 'information_source', | ||
]), | ||
], | ||
]); | ||
} | ||
|
||
/** | ||
|
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't 100% understand the need to create the
UPDATE_PARALLEL_PROCESSES
constant here to call out the name of the environment variable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* waves hand over it *
To make it look more fancy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.