Files
toolbox/app/Console/Commands/ScheduledTaskRefreshCommand.php

41 lines
1.2 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Services\ScheduledTaskService;
use Illuminate\Console\Command;
class ScheduledTaskRefreshCommand extends Command
{
protected $signature = 'scheduled-task:refresh';
protected $description = '刷新定时任务列表,同步 console.php 中的任务配置到数据库';
public function handle(ScheduledTaskService $taskService): int
{
try {
$this->info('开始刷新定时任务列表...');
$tasks = $taskService->getAllTasks();
$this->info(sprintf('成功刷新 %d 个定时任务', count($tasks)));
// 显示任务列表
$this->table(
['任务名称', '描述', '执行频率', '状态'],
array_map(fn($task) => [
$task['name'],
$task['description'],
$task['frequency'],
$task['enabled'] ? '已启用' : '已禁用',
], $tasks)
);
return Command::SUCCESS;
} catch (\Exception $e) {
$this->error("刷新失败: {$e->getMessage()}");
return Command::FAILURE;
}
}
}