78 lines
2.1 KiB
PHP
78 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Utilities;
|
|
|
|
use App\Actions\SupervisorMaker;
|
|
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;
|
|
$maker = $options['x'] ?? 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 ($maker) {
|
|
SupervisorMaker::run($supervisor);
|
|
}
|
|
|
|
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 {
|
|
if ($options['is_cron']) {
|
|
Notice::note('cron process timings set in crontab', 'b');
|
|
} else {
|
|
Notice::note('in production process sleeps for '.$options['sleep'].'sec', 'b');
|
|
}
|
|
}
|
|
}
|
|
|
|
if (! $options['is_active']) {
|
|
Notice::note('Process disabled, sleeps 2 min then exit', 'r');
|
|
sleep(120);
|
|
exit;
|
|
}
|
|
|
|
} 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');
|
|
}
|
|
}
|
|
}
|