42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\ScheduledTaskService;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class ScheduledTaskRefreshCommand extends Command
|
|
{
|
|
protected $signature = 'scheduled-task:refresh';
|
|
|
|
protected $description = '刷新定时任务列表,同步 console.php 中的任务配置到数据库';
|
|
|
|
public function handle(ScheduledTaskService $taskService): int
|
|
{
|
|
try {
|
|
Log::channel('scheduled-tasks')->info('开始刷新定时任务列表...');
|
|
|
|
$tasks = $taskService->getAllTasks();
|
|
|
|
Log::channel('scheduled-tasks')->info(sprintf('成功刷新 %d 个定时任务', count($tasks)));
|
|
|
|
// 显示任务列表
|
|
foreach ($tasks as $task) {
|
|
Log::channel('scheduled-tasks')->info(sprintf(
|
|
' - %s: %s (%s) [%s]',
|
|
$task['name'],
|
|
$task['description'],
|
|
$task['frequency'],
|
|
$task['enabled'] ? '已启用' : '已禁用'
|
|
));
|
|
}
|
|
|
|
return Command::SUCCESS;
|
|
} catch (\Exception $e) {
|
|
Log::channel('scheduled-tasks')->error("刷新失败: {$e->getMessage()}");
|
|
return Command::FAILURE;
|
|
}
|
|
}
|
|
}
|