Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Nov 9, 2024
1 parent f5f732d commit feaf4f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/Tempest/CommandBus/src/HandleAsyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use Tempest\Console\ExitCode;
use Tempest\Console\HasConsole;
use Tempest\Container\Container;
use Throwable;
use function Tempest\Support\arr;
use Throwable;

final readonly class HandleAsyncCommand
{
Expand All @@ -21,7 +21,8 @@ public function __construct(
private Container $container,
private Console $console,
private CommandRepository $repository,
) {}
) {
}

#[ConsoleCommand(name: 'command:handle')]
public function __invoke(?string $uuid = null): ExitCode
Expand All @@ -35,6 +36,7 @@ public function __invoke(?string $uuid = null): ExitCode

if (! $command) {
$this->error('No pending command found');

return ExitCode::ERROR;
}

Expand All @@ -43,6 +45,7 @@ public function __invoke(?string $uuid = null): ExitCode
if (! $commandHandler) {
$commandClass = $command::class;
$this->error("No handler found for command {$commandClass}");

return ExitCode::ERROR;
}

Expand All @@ -53,10 +56,12 @@ public function __invoke(?string $uuid = null): ExitCode

$this->repository->markAsDone($uuid);
$this->success('Done');

return ExitCode::SUCCESS;
} catch (Throwable $throwable) {
$this->repository->markAsFailed($uuid);
$this->error($throwable->getMessage());

return ExitCode::ERROR;
}
}
Expand Down
9 changes: 7 additions & 2 deletions tests/Integration/CommandBus/AsyncCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
use Tempest\CommandBus\AsyncCommandRepositories\MemoryRepository;
use Tempest\CommandBus\CommandRepository;
use Tempest\Highlight\Themes\TerminalStyle;
use function Tempest\Support\arr;
use Tests\Tempest\Fixtures\Handlers\MyAsyncCommandHandler;
use Tests\Tempest\Integration\CommandBus\Fixtures\MyAsyncCommand;
use Tests\Tempest\Integration\FrameworkIntegrationTestCase;
use function Tempest\Support\arr;

/**
* @internal
Expand All @@ -25,7 +25,7 @@ public function test_async_commands_are_stored_and_handled_afterwards(): void

$this->container->singleton(
CommandRepository::class,
fn () => $repository
fn () => $repository,
);

MyAsyncCommandHandler::$isHandled = false;
Expand Down Expand Up @@ -78,6 +78,11 @@ public function test_async_failed_command_monitor(): void
$this->assertStringContainsString('failed at', $output);
$this->assertStringContainsString('Failed command', $output);
$process->stop();

arr(glob(__DIR__ . '/../../../src/Tempest/CommandBus/src/stored-commands/*.failed.txt'))
->each(function (string $filename): void {
unlink($filename);
});
}

private function getOutput(Process $process): string
Expand Down

0 comments on commit feaf4f9

Please # to comment.