Files
nuhodds_fi4/app/Utilities/Supervisorctl.php
T
2026-01-16 12:28:33 +01:00

111 lines
3.2 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;
$runanyway = $options['f'] ?? 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)->toArray();
if (isset($supervisor['sport']['name'])) {
$supervisor['sport'] = $supervisor['sport']['name'];
}
if ($supervisor['provider']) {
$supervisor['provider_id'] = $supervisor['provider']['id'];
$supervisor['base_url'] = $supervisor['provider']['base_url'];
$supervisor['provider'] = $supervisor['provider']['name'];
}
$options = array_merge($options, $supervisor);
if ($maker) {
SupervisorMaker::run($supervisor);
}
if ($supervisor) {
if ($debug) {
Notice::note('supervisor start '.self::$code, 'g');
}
if ($proxy) {
$options['proxy'] = 'https://prox2.nuhodds.com/proxy.php';
}
if ($options['sleep'] > 0) {
if (! $debug) {
sleep($options['sleep']);
} else {
if ($options['is_supervisor']) {
Notice::note('cron process', 'b');
} else {
Notice::note('production sleeps '.$options['sleep'].'sec', 'b');
}
}
}
switch ($options['provider_id']) {
case 3:
// MAGLOO KENIA
$options['bookmaker_id'] = 16;
break;
case 4:
// MAGLOO NIGERIA
$options['bookmaker_id'] = 10;
break;
case 5:
// LOGIFUTURE NIGERA
$options['bookmaker_id'] = 35;
break;
case 6:
// LOGIFUTURE COLOMBIA
$options['bookmaker_id'] = 36;
break;
case 9:
// BETICA
$options['bookmaker_id'] = 14;
break;
}
if (! $options['is_active'] && ! $runanyway) {
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');
}
}
}