Skip to content

Commit

Permalink
CLI-1101: Set exit code 1 when a task waited command fails (#1559)
Browse files Browse the repository at this point in the history
Co-authored-by: Dane Powell <[email protected]>
  • Loading branch information
cdubz and danepowell committed Jun 30, 2023
1 parent 2216764 commit ec7d31c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/Command/App/TaskWaitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ protected function configure(): void {

protected function execute(InputInterface $input, OutputInterface $output): int {
$notificationUuid = $this->getNotificationUuid($input);
$this->waitForNotificationToComplete($this->cloudApiClientService->getClient(), $notificationUuid, "Waiting for task $notificationUuid to complete");
return Command::SUCCESS;
$success = $this->waitForNotificationToComplete($this->cloudApiClientService->getClient(), $notificationUuid, "Waiting for task $notificationUuid to complete");
if ($success) {
return Command::SUCCESS;
}
else {
return Command::FAILURE;
}
}

private function getNotificationUuid(InputInterface $input): string {
Expand Down
3 changes: 2 additions & 1 deletion src/Command/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@ protected function checkAuthentication(): void {
}
}

protected function waitForNotificationToComplete(Client $acquiaCloudClient, string $uuid, string $message, callable $success = NULL): void {
protected function waitForNotificationToComplete(Client $acquiaCloudClient, string $uuid, string $message, callable $success = NULL): bool {
$notificationsResource = new Notifications($acquiaCloudClient);
$notification = NULL;
$checkNotificationStatus = static function () use ($notificationsResource, &$notification, $uuid): bool {
Expand All @@ -1451,6 +1451,7 @@ protected function waitForNotificationToComplete(Client $acquiaCloudClient, stri
};
}
LoopHelper::getLoopy($this->output, $this->io, $this->logger, $message, $checkNotificationStatus, $success);
return $notification->status === 'completed';
}

private function writeCompletedMessage(NotificationResponse $notification): void {
Expand Down
5 changes: 4 additions & 1 deletion tests/phpunit/src/Commands/App/TaskWaitCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function createCommand(): Command {
/**
* @dataProvider providerTestTaskWaitCommand
*/
public function testTaskWaitCommand(string $status, string $message): void {
public function testTaskWaitCommand(string $status, string $message, int $statusCode): void {
$notificationUuid = '94835c3e-b112-4660-a14d-d541906c205b';
$this->mockNotificationResponse($notificationUuid, $status);
$this->executeCommand([
Expand All @@ -36,6 +36,7 @@ public function testTaskWaitCommand(string $status, string $message): void {
$this->assertStringContainsString('Completed: Mon Jul 29 20:47:13 UTC 2019', $output);
$this->assertStringContainsString('Task type: Application added to recents list', $output);
$this->assertStringContainsString('Duration: 0 seconds', $output);
$this->assertEquals($statusCode, $this->getStatusCode());
}

/**
Expand All @@ -46,10 +47,12 @@ public function providerTestTaskWaitCommand(): array {
[
'completed',
' [OK] The task with notification uuid 1bd3487e-71d1-4fca-a2d9-5f969b3d35c1 completed',
Command::SUCCESS,
],
[
'failed',
' [ERROR] The task with notification uuid 1bd3487e-71d1-4fca-a2d9-5f969b3d35c1 failed',
Command::FAILURE,
],
];
}
Expand Down

0 comments on commit ec7d31c

Please sign in to comment.