[色子游戏]玩家抽奖记录测试数据
This commit is contained in:
44
server/app/process/WeightTestProcess.php
Normal file
44
server/app/process/WeightTestProcess.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user