55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Jobs\RunCrawlRuleJob;
|
|
use App\Models\CrawlRun;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
class CrawlRunController extends Controller
|
|
{
|
|
public function index(Request $request): View
|
|
{
|
|
$items = CrawlRun::query()
|
|
->with('rule')
|
|
->when($request->filled('rule_id'), function ($query) use ($request): void {
|
|
$query->where('rule_id', (int) $request->input('rule_id'));
|
|
})
|
|
->latest('id')
|
|
->paginate(20)
|
|
->withQueryString();
|
|
|
|
return view('admin.crawl-runs.index', [
|
|
'items' => $items,
|
|
'filters' => $request->only(['rule_id']),
|
|
]);
|
|
}
|
|
|
|
public function show(CrawlRun $run): View
|
|
{
|
|
$run->load(['rule', 'items' => function ($query): void {
|
|
$query->latest('id');
|
|
}, 'alerts']);
|
|
|
|
return view('admin.crawl-runs.show', [
|
|
'run' => $run,
|
|
]);
|
|
}
|
|
|
|
public function retry(CrawlRun $run): RedirectResponse
|
|
{
|
|
if ($run->rule_id !== null) {
|
|
RunCrawlRuleJob::dispatch($run->rule_id, 'retry', null, $run->id);
|
|
}
|
|
|
|
return redirect()->route('admin.crawl-runs.index', ['rule_id' => $run->rule_id])
|
|
->with('status', '已提交重试任务');
|
|
}
|
|
}
|
|
|