Skip to content
Merged
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
39 changes: 39 additions & 0 deletions src/Command/HealthCheckJsonCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;

#[AsCommand('frosh-tools:health-check-json', 'Returns a JSON with all health check checkers result merged like with /health/status route')]
class HealthCheckJsonCommand extends Command
{
/**
* @param CheckerInterface[] $healthCheckers
*/
public function __construct(
#[AutowireIterator('frosh_tools.health_checker')]
private readonly iterable $healthCheckers,
) {
parent::__construct();
}

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 | \JSON_THROW_ON_ERROR));

return Command::SUCCESS;
}
}
2 changes: 1 addition & 1 deletion src/Command/RedisNamespaceCleanupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if (!isset($namespaces[$namespace])) {
$namespaces[$namespace] = [
'count' => 0,
'isActive' => $this->isActiveNamespace($namespace, $activeNamespaces)
'isActive' => $this->isActiveNamespace($namespace, $activeNamespaces),
];
}
++$namespaces[$namespace]['count'];
Expand Down