爬虫开发
Some checks failed
Tests / PHP 8.2 (push) Has been cancelled
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled

This commit is contained in:
cjd
2026-02-18 12:56:36 +08:00
parent a98bc6f13c
commit 260460df03
45 changed files with 4091 additions and 8 deletions

View File

@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace App\Jobs;
use App\Enums\CrawlTriggerType;
use App\Models\CrawlRule;
use App\Services\Crawler\CrawlExecutionService;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Queue\SerializesModels;
class RunCrawlRuleJob implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
public function __construct(
public readonly int $ruleId,
public readonly string $triggerType,
public readonly ?int $createdBy = null,
public readonly ?int $retryFromRunId = null,
) {
}
public function handle(CrawlExecutionService $executionService): void
{
$rule = CrawlRule::query()->find($this->ruleId);
if (! $rule instanceof CrawlRule) {
return;
}
$trigger = CrawlTriggerType::tryFrom($this->triggerType) ?? CrawlTriggerType::Manual;
$metrics = [];
if ($this->retryFromRunId !== null) {
$metrics['retry_from_run_id'] = $this->retryFromRunId;
}
$executionService->runRule($rule, $trigger, $this->createdBy, $metrics);
}
}