Files
nuhodds_fi4/app/Utilities/Supervisorctl.php
T
2025-08-14 16:05:36 +02:00

58 lines
1.5 KiB
PHP

<?php
namespace App\Utilities;
use App\Models\Supervisor;
class Supervisorctl
{
public static $starttime = 0;
public static $code = '';
public static $events = 0;
public static function start(&$options)
{
$debug = $options['d'] ?? 0;
// sleep 1 sec to avoid error in supervisor
sleep(1);
self::$starttime = microtime(true);
self::$code = $options['code'];
$supervisor = Supervisor::where('code', self::$code)->get()->first();
// if process can be called only from bash
if ($supervisor) {
$options['sport_id'] = $supervisor->sport_id;
$options['customer_id'] = $supervisor->customer_id;
$options['limit'] = $supervisor->limit;
if ($debug) {
Notice::note('supervisor start '.self::$code, 'g');
}
if ($supervisor->sleep > 0) {
if (! $debug) {
sleep($supervisor->sleep);
}
}
} else {
Notice::note('unknown supervisor: '.$options['code'], 'r', 1);
}
}
public static function end($options)
{
$processend = microtime(true);
$runtime = round(($processend - self::$starttime) / 60, 3);
Supervisor::where('code', self::$code)->update(['runtime' => $runtime, 'events' => self::$events]);
if ($options['d']) {
Notice::note('spervisor time: '.$runtime.' min', 'g');
}
}
}