feat(timer): 新增日志每日自动清理定时任务

- New LogClean timer controller (site type, frequency 86400s)
- run_type defaults to auto, only one node cleans per day
- Cleans system_timer_log records older than 30 days
This commit is contained in:
augushong
2026-05-26 17:20:10 +08:00
parent fd89a60425
commit e1bf94a55e
3 changed files with 43 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace app\tools\controller\timer;
use base\tools\controller\timer\LogCleanBase;
class LogClean extends LogCleanBase
{
}

View File

@@ -14,4 +14,11 @@ return [
'frequency' => 600,
'concurrency' => 1,
],
[
'name' => 'timer_log_clean',
'type' => 'site',
'target' => '/tools/timer.LogClean/do',
'frequency' => 86400,
'concurrency' => 1,
],
];

View File

@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace base\tools\controller\timer;
use app\common\controller\TimerController;
use think\facade\Db;
class LogCleanBase extends TimerController
{
protected $frequency = 86400;
public function do()
{
$days = 30;
$threshold = time() - ($days * 86400);
$count = Db::name('system_timer_log')
->where('create_time', '<', $threshold)
->delete();
return "已清理 {$count} 条超过 {$days} 天的定时器执行日志。";
}
}