#feature: add project&cronjob management

This commit is contained in:
2026-01-16 12:14:43 +08:00
parent bbe68839e3
commit 381d5e6e49
19 changed files with 2157 additions and 84 deletions

View File

@@ -1,6 +1,5 @@
<?php
use App\Services\ConfigService;
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;
@@ -16,7 +15,8 @@ Artisan::command('inspire', function () {
|--------------------------------------------------------------------------
|
| 定时任务配置
| 所有定时任务统一在此文件管理
| 所有任务可在管理后台的"定时任务"页面控制启用/禁用
| 启用状态存储在数据库 configs (key: scheduled_tasks)
|
*/
@@ -25,50 +25,34 @@ Schedule::command('git-monitor:check')
->everyTenMinutes()
->withoutOverlapping()
->runInBackground()
->name('git-monitor-check');
->name('git-monitor-check')
->description('Git 监控 - 检查 release 分支变化')
->when(fn() => \App\Services\ScheduledTaskService::isEnabled('git-monitor-check'));
// Git Monitor - 每天凌晨 2 点刷新 release 缓存
Schedule::command('git-monitor:cache')
->dailyAt('02:00')
->withoutOverlapping()
->name('git-monitor-cache');
->name('git-monitor-cache')
->description('Git 监控 - 刷新 release 缓存')
->when(fn() => \App\Services\ScheduledTaskService::isEnabled('git-monitor-cache'));
// SLS 日志分析定时任务 - 每天凌晨 2 点执行
// 分析过去 24 小时的 ERROR 和 WARNING 日志并推送到钉钉
// 可通过数据库配置 log_analysis.settings.daily_schedule_enabled 控制是否启用
// SLS 日志分析 - 每天凌晨 2 点执行
Schedule::command('log-analysis:run --from="-24h" --to="now" --query="ERROR or WARNING" --push')
->dailyAt('02:00')
->withoutOverlapping()
->runInBackground()
->when(function () {
try {
$settings = app(ConfigService::class)->get('log_analysis.settings', []);
return $settings['daily_schedule_enabled'] ?? false;
} catch (\Exception $e) {
return false;
}
})
->name('daily-log-analysis')
->onFailure(function () {
Log::error('每日日志分析定时任务执行失败');
});
->description('SLS 日志分析 - 每日分析过去 24 小时日志')
->when(fn() => \App\Services\ScheduledTaskService::isEnabled('daily-log-analysis'))
->onFailure(fn() => Log::error('每日日志分析定时任务执行失败'));
// SLS 日志分析定时任务 - 每 4 小时执行一次
// 分析过去 6 小时的 ERROR 和 WARNING 日志并推送到钉钉
// 可通过数据库配置 log_analysis.settings.schedule_enabled 控制是否启用
// SLS 日志分析 - 每 4 小时执行一次
Schedule::command('log-analysis:run --from="-6h" --to="now" --query="ERROR or WARNING" --push')
->everyFourHours()
->withoutOverlapping()
->runInBackground()
->when(function () {
try {
$settings = app(ConfigService::class)->get('log_analysis.settings', []);
return $settings['schedule_enabled'] ?? false;
} catch (\Exception $e) {
return false;
}
})
->name('frequent-log-analysis')
->onFailure(function () {
Log::error('SLS 日志分析定时任务执行失败');
});
->description('SLS 日志分析 - 定期分析过去 6 小时日志')
->when(fn() => \App\Services\ScheduledTaskService::isEnabled('frequent-log-analysis'))
->onFailure(fn() => Log::error('SLS 日志分析定时任务执行失败'));