Files
nuhodds_fi4/app/Utilities/Supervisorctl.php
T

62 lines
1.6 KiB
PHP

<?php
namespace App\Utilities;
use App\Models\Provider;
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::find(self::$code);
if ($supervisor) {
if ($debug) {
Notice::note('supervisor start '.self::$code, 'g');
}
$options = array_merge($options, $supervisor->toArray());
$options['process'] = Provider::where('id', $options['provider_id'])->value('name');
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');
}
}
}