From 7312da3f35aeda98d9a68e4d4436c2a4ec368750 Mon Sep 17 00:00:00 2001 From: Shyim Date: Thu, 6 Feb 2025 16:33:38 +0100 Subject: [PATCH] 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). --- src/Command/HealthCheckJsonCommand.php | 45 ++++++++++++++++++++++++++ src/Resources/config/services.xml | 1 + 2 files changed, 46 insertions(+) create mode 100644 src/Command/HealthCheckJsonCommand.php diff --git a/src/Command/HealthCheckJsonCommand.php b/src/Command/HealthCheckJsonCommand.php new file mode 100644 index 00000000..3edec3a0 --- /dev/null +++ b/src/Command/HealthCheckJsonCommand.php @@ -0,0 +1,45 @@ +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; + } +} diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 45a1f9ac..83bd460b 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -7,5 +7,6 @@ +