Skip to content
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

Add frosh-tools:health-check-json command #312

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/Command/HealthCheckJsonCommand.php
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

View workflow job for this annotation

GitHub Actions / phpstan / Static Analyse

Out of 20 possible property types, only 19 - 95.0 % actually have it. Add more property types to get over 100 %

Check failure on line 16 in src/Command/HealthCheckJsonCommand.php

View workflow job for this annotation

GitHub Actions / phpstan / Static Analyse

Property Frosh\Tools\Command\HealthCheckJsonCommand::$defaultName has no type specified.

/**
* @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));

Check failure on line 41 in src/Command/HealthCheckJsonCommand.php

View workflow job for this annotation

GitHub Actions / phpstan / Static Analyse

Parameter #1 $messages of method Symfony\Component\Console\Output\OutputInterface::writeln() expects iterable<string>|string, string|false given.

return Command::SUCCESS;
}
}
1 change: 1 addition & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<services>
<defaults autowire="true" autoconfigure="true" />
<prototype namespace="Frosh\Tools\" resource="../../" exclude="../../{DependencyInjection,Resources,FroshTools.php}" />
<service id="Frosh\Tools\Command\HealthCheckJsonCommand" />
</services>
</container>
Loading