mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-08 02:52:49 +08:00
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:
11
app/tools/controller/timer/LogClean.php
Normal file
11
app/tools/controller/timer/LogClean.php
Normal 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
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -14,4 +14,11 @@ return [
|
|||||||
'frequency' => 600,
|
'frequency' => 600,
|
||||||
'concurrency' => 1,
|
'concurrency' => 1,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'name' => 'timer_log_clean',
|
||||||
|
'type' => 'site',
|
||||||
|
'target' => '/tools/timer.LogClean/do',
|
||||||
|
'frequency' => 86400,
|
||||||
|
'concurrency' => 1,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
25
extend/base/tools/controller/timer/LogCleanBase.php
Normal file
25
extend/base/tools/controller/timer/LogCleanBase.php
Normal 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} 天的定时器执行日志。";
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user