Files
dafuweng-saiadmin6.x/server/app/process/WeightTestProcess.php

45 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace app\process;
use app\dice\logic\reward_config_record\WeightTestRunner;
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
use Workerman\Timer;
use Workerman\Worker;
/**
* 一键测试权重定时任务进程:每隔一定时间检查 status=0 的测试记录并执行一条,不占用 HTTP worker 资源
*/
class WeightTestProcess
{
/** 轮询间隔(秒) */
private const INTERVAL = 15;
public function onWorkerStart(Worker $worker): void
{
Timer::add(self::INTERVAL, function () {
$this->runOnePending();
});
}
/**
* 执行一条待完成的测试记录status=0
*/
private function runOnePending(): void
{
$record = DiceRewardConfigRecord::where('status', DiceRewardConfigRecord::STATUS_RUNNING)
->order('id')
->find();
if (!$record) {
return;
}
$recordId = (int) $record->id;
try {
(new WeightTestRunner())->run($recordId);
} catch (\Throwable $e) {
// WeightTestRunner 内部会更新 status=-1 和 remark
}
}
}