Files
ai-web/app/Console/Commands/CrawlerRetryFailedCommand.php

40 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2026-02-18 12:56:36 +08:00
<?php
declare(strict_types=1);
namespace App\Console\Commands;
use App\Enums\CrawlTriggerType;
use App\Jobs\RunCrawlRuleJob;
use App\Models\CrawlRun;
use Illuminate\Console\Command;
class CrawlerRetryFailedCommand extends Command
{
protected $signature = 'crawler:retry-failed {runId : 待重试的运行ID} {--sync : 同步执行,不走队列}';
protected $description = '重试失败的采集运行(按原规则重跑)';
public function handle(): int
{
$run = CrawlRun::query()->with('rule')->find((int) $this->argument('runId'));
if (! $run instanceof CrawlRun || $run->rule === null) {
$this->error('运行记录不存在或规则已删除');
return self::FAILURE;
}
if ((bool) $this->option('sync')) {
RunCrawlRuleJob::dispatchSync($run->rule_id, CrawlTriggerType::Retry->value, null, $run->id);
} else {
RunCrawlRuleJob::dispatch($run->rule_id, CrawlTriggerType::Retry->value, null, $run->id);
}
$this->info(sprintf('已提交重试任务,规则 #%d %s', $run->rule_id, $run->rule->name));
return self::SUCCESS;
}
}