Files
nuhodds_fi4/app/Utilities/Supervisorctl.php
T
2026-01-08 12:51:12 +01:00

62 lines
1.6 KiB
PHP

<?php
namespace App\Utilities;
use App\Models\Supervisor;
class Supervisorctl
{
public static $starttime = 0;
public static $code = '';
public static function start(&$options)
{
$debug = $options['d'] ?? 0;
$proxy = $options['p'] ?? 0;
// sleep for 0,5 seconds
usleep(500000);
self::$starttime = microtime(true);
self::$code = $options['supervisor_id'];
$supervisor = Supervisor::with('sport')->with('provider')->find(self::$code);
if ($supervisor) {
if ($debug) {
Notice::note('supervisor start '.self::$code, 'g');
}
$tmp = $supervisor->toArray();
unset($tmp['id']);
$options = array_merge($options, $tmp);
if ($proxy) {
$options['proxy'] = 'https://prox2.nuhodds.com/proxy.php';
}
if ($options['sleep'] > 0) {
if (! $debug) {
sleep($options['sleep']);
} else {
Notice::note('without debug process sleeps for '.$options['sleep'].'sec', 'g');
}
}
} else {
Notice::note('unknown supervisor: '.self::$code, 'r', 1);
}
}
public static function end($options)
{
$processend = microtime(true);
$runtime = round(($processend - self::$starttime) / 60, 3);
Supervisor::where('id', self::$code)->update(['runtime' => $runtime]);
if ($options['d']) {
Notice::note('spervisor time: '.$runtime.' min', 'g');
}
}
}