Files
toolbox/routes/console.php
2026-01-19 15:42:44 +08:00

70 lines
2.6 KiB
PHP

<?php
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Schedule;
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote');
/*
|--------------------------------------------------------------------------
| Scheduled Tasks
|--------------------------------------------------------------------------
|
| 定时任务配置
| 所有任务可在管理后台的"定时任务"页面控制启用/禁用
| 启用状态存储在数据库 configs 表 (key: scheduled_tasks)
|
*/
// Git Monitor - 每 10 分钟检查 release 分支
Schedule::command('git-monitor:check')
->everyTenMinutes()
->withoutOverlapping()
->runInBackground()
->description('git-monitor-check')
->when(fn() => \App\Services\ScheduledTaskService::isEnabled('git-monitor-check'));
// Git Monitor - 每天凌晨 2 点刷新 release 缓存
Schedule::command('git-monitor:cache')
->dailyAt('02:00')
->withoutOverlapping()
->description('git-monitor-cache')
->when(fn() => \App\Services\ScheduledTaskService::isEnabled('git-monitor-cache'));
// SLS 日志分析 - 每天凌晨 2 点执行
Schedule::command('log-analysis:run --from="-24h" --to="now" --query="ERROR or WARNING" --push')
->dailyAt('02:00')
->withoutOverlapping()
->runInBackground()
->description('daily-log-analysis')
->when(fn() => \App\Services\ScheduledTaskService::isEnabled('daily-log-analysis'))
->onFailure(fn() => Log::error('每日日志分析定时任务执行失败'));
// SLS 日志分析 - 每 4 小时执行一次
Schedule::command('log-analysis:run --from="-6h" --to="now" --query="ERROR or WARNING" --push')
->everyFourHours()
->withoutOverlapping()
->runInBackground()
->description('frequent-log-analysis')
->when(fn() => \App\Services\ScheduledTaskService::isEnabled('frequent-log-analysis'))
->onFailure(fn() => Log::error('SLS 日志分析定时任务执行失败'));
// Jenkins Monitor - 每分钟检查新构建
Schedule::command('jenkins:monitor')
->everyMinute()
->withoutOverlapping()
->runInBackground()
->description('jenkins-monitor')
->when(fn() => \App\Services\ScheduledTaskService::isEnabled('jenkins-monitor'));
// 定时任务刷新 - 每天凌晨 3 点刷新定时任务列表
Schedule::command('scheduled-task:refresh')
->dailyAt('03:00')
->withoutOverlapping()
->description('scheduled-task-refresh')
->when(fn() => \App\Services\ScheduledTaskService::isEnabled('scheduled-task-refresh'));