webcron/src/Controller/SiteController.php

29 lines
1.0 KiB
PHP
Raw Normal View History

2022-02-04 14:21:42 +01:00
<?php
2022-04-27 14:24:48 +02:00
namespace App\Controller;
2022-02-04 14:21:42 +01:00
2022-05-06 11:42:41 +02:00
use App\Entity\Job;
use App\Service\DaemonHelpers;
2022-04-27 14:24:48 +02:00
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
2022-02-04 14:21:42 +01:00
use Symfony\Component\HttpFoundation\JsonResponse;
2022-04-27 14:24:48 +02:00
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\KernelInterface;
2022-02-04 14:21:42 +01:00
2022-04-27 14:24:48 +02:00
class SiteController extends AbstractController
2022-02-04 14:21:42 +01:00
{
2022-04-27 14:24:48 +02:00
public function healthAction(Request $request, ManagerRegistry $doctrine, KernelInterface $kernel)
2022-02-04 14:21:42 +01:00
{
2022-04-27 14:24:48 +02:00
$em = $doctrine->getManager();
2022-05-06 11:42:41 +02:00
$jobRepo = $em->getRepository(Job::class);
2022-02-04 14:21:42 +01:00
$return = [
"DaemonRunning" => DaemonHelpers::isProcessRunning($kernel->getCacheDir() . '/daemon-running.lock'),
2022-02-04 14:21:42 +01:00
"JobsTotal" => count($jobRepo->getAllJobs()),
"JobsDue" => count($jobRepo->getJobsDue()),
"JobsRunning" => count($jobRepo->getRunningJobs()),
"JobsFailing" => count($jobRepo->getFailingJobs()),
];
return new JsonResponse($return, $return['DaemonRunning'] ? 200 : 500);
}
}