mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 15:32:48 +08:00
feat(timer): 新增 run_type 调度、host_id 投递和日志清理
T7: TimerBase shouldExecuteTask() - main/auto/all/manual/disabled modes
with two-phase DB row lock for auto mode
T8: TimerControllerBase - host_id param, logStart/logEnd methods
TimerServiceBase - inject host_id into site URLs
T9: TimerLogClean command - php think admin:timer:log:clean --days=30
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace base\common\controller;
|
||||
|
||||
use app\admin\model\SystemTimerLog;
|
||||
use app\common\controller\ToolsController;
|
||||
use think\facade\Cache;
|
||||
|
||||
@@ -13,6 +14,8 @@ class TimerControllerBase extends ToolsController
|
||||
|
||||
protected $concurrencyId = 0;
|
||||
|
||||
protected $hostId = null;
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
@@ -28,6 +31,8 @@ class TimerControllerBase extends ToolsController
|
||||
$this->error('concurrency count error');
|
||||
}
|
||||
|
||||
$this->hostId = $this->request->param('host_id', '');
|
||||
|
||||
if (is_int($this->frequency)) {
|
||||
$this->protectVisit($this->frequency);
|
||||
}
|
||||
@@ -47,4 +52,35 @@ class TimerControllerBase extends ToolsController
|
||||
|
||||
Cache::tag($cache_tag)->set($cache_key, time());
|
||||
}
|
||||
|
||||
public function logStart(string $taskName): int
|
||||
{
|
||||
$data = [
|
||||
'task_name' => $taskName,
|
||||
'node_id' => $this->hostId,
|
||||
'run_type' => '',
|
||||
'start_time' => time(),
|
||||
'end_time' => 0,
|
||||
'duration' => 0,
|
||||
'status' => 'running',
|
||||
'error_message' => null,
|
||||
'concurrency_id' => $this->concurrencyId,
|
||||
'create_time' => time(),
|
||||
];
|
||||
$log = SystemTimerLog::create($data);
|
||||
return $log->id;
|
||||
}
|
||||
|
||||
public function logEnd(int $logId, string $status = 'success', ?string $errorMessage = null): void
|
||||
{
|
||||
$log = SystemTimerLog::find($logId);
|
||||
if ($log) {
|
||||
$endTime = time();
|
||||
$log->end_time = $endTime;
|
||||
$log->duration = ($endTime - $log->start_time) * 1000; // ms
|
||||
$log->status = $status;
|
||||
$log->error_message = $errorMessage;
|
||||
$log->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user