55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace External\ZNZBundle\Controller;
|
|
|
|
use External\ZNZBundle\Util\ZNZApi;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
class ZNZMonitoringController extends AbstractController
|
|
{
|
|
#[Route('/_znz/monitoring/changes-count/')]
|
|
public function heliosChangesCount(ZNZApi $api): Response
|
|
{
|
|
$dbcfg = \Settings::getDefault();
|
|
|
|
$monitoring = $dbcfg->loadValue('znz_monitoring') ?: [];
|
|
|
|
$lastChangesCount = $monitoring['changesCount'] ?? null;
|
|
|
|
try {
|
|
$monitoring['changesCount'] = $currentChangesCount = $api->getChangesCount();
|
|
} catch (\Throwable $e) {
|
|
// chyba pri zjistovani poctu zmen ve fronte - nejspis se tam neda pripojit
|
|
// tak to nechci do monitoringu, protoze to je jejich problem
|
|
return new Response('1');
|
|
}
|
|
|
|
$isOK = 1;
|
|
|
|
if ($lastChangesCount !== null) {
|
|
$diff = $currentChangesCount - $lastChangesCount;
|
|
if ($diff >= 0) {
|
|
$isOK = 0;
|
|
}
|
|
}
|
|
|
|
// kdyz nemam data, tak neni co kontrolovat
|
|
if ($lastChangesCount === null) {
|
|
$isOK = 1;
|
|
}
|
|
|
|
// pokud je aktualni pocet zmen 0, tak je to OK
|
|
if ($currentChangesCount === 0) {
|
|
$isOK = 1;
|
|
}
|
|
|
|
$dbcfg->saveValue('znz_monitoring', $monitoring, false);
|
|
|
|
return new Response((string) $isOK);
|
|
}
|
|
}
|