-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add frosh-tools:health-check-json command
Add a new command `frosh-tools:health-check-json` to return a JSON with all health check checkers result merged like with `/health/status` route. * Create `HealthCheckJsonCommand` class in `src/Command/HealthCheckJsonCommand.php` - Implement the `Command` class from `Symfony\Component\Console\Command\Command` - Inject health checkers in the constructor - Implement the `execute` method to collect health check results and return as JSON - Register the command with the name `frosh-tools:health-check-json` * Modify `src/Resources/config/services.xml` - Register the new `HealthCheckJsonCommand` class as a service --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/FriendsOfShopware/FroshTools?shareId=XXXX-XXXX-XXXX-XXXX).
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Frosh\Tools\Command; | ||
|
||
use Frosh\Tools\Components\Health\Checker\CheckerInterface; | ||
use Frosh\Tools\Components\Health\HealthCollection; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator; | ||
|
||
class HealthCheckJsonCommand extends Command | ||
{ | ||
protected static $defaultName = 'frosh-tools:health-check-json'; | ||
Check failure on line 16 in src/Command/HealthCheckJsonCommand.php
|
||
|
||
/** | ||
* @param CheckerInterface[] $healthCheckers | ||
*/ | ||
public function __construct( | ||
#[AutowireIterator('frosh_tools.health_checker')] | ||
private readonly iterable $healthCheckers, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this | ||
->setDescription('Returns a JSON with all health check checkers result merged like with /health/status route'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$collection = new HealthCollection(); | ||
foreach ($this->healthCheckers as $checker) { | ||
$checker->collect($collection); | ||
} | ||
|
||
$output->writeln(json_encode($collection, JSON_PRETTY_PRINT)); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters