爬虫开发
This commit is contained in:
54
app/Http/Controllers/Admin/CrawlRunController.php
Normal file
54
app/Http/Controllers/Admin/CrawlRunController.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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', '已提交重试任务');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user