爬虫开发
This commit is contained in:
41
app/Console/Commands/CrawlerHealthCheckCommand.php
Normal file
41
app/Console/Commands/CrawlerHealthCheckCommand.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class CrawlerHealthCheckCommand extends Command
|
||||
{
|
||||
protected $signature = 'crawler:health-check';
|
||||
|
||||
protected $description = '采集器依赖与配置自检';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$checks = [
|
||||
['item' => 'Queue Connection', 'status' => (string) config('queue.default'), 'detail' => '当前队列连接'],
|
||||
['item' => 'Browserless Endpoint', 'status' => (string) (config('crawler.browserless_endpoint') ?: 'not-configured'), 'detail' => 'JS渲染服务'],
|
||||
['item' => 'AI Endpoint', 'status' => (string) (config('crawler.openai_compatible_endpoint') ?: 'not-configured'), 'detail' => 'AI兜底抽取'],
|
||||
['item' => 'Alert Email', 'status' => (string) (config('crawler.default_alert_email') ?: 'not-configured'), 'detail' => '默认告警邮箱'],
|
||||
];
|
||||
|
||||
$browserlessEndpoint = (string) config('crawler.browserless_endpoint', '');
|
||||
|
||||
if ($browserlessEndpoint !== '') {
|
||||
try {
|
||||
$response = Http::timeout(5)->get($browserlessEndpoint);
|
||||
$checks[] = ['item' => 'Browserless Reachable', 'status' => $response->status() < 500 ? 'ok' : 'degraded', 'detail' => 'HTTP '.$response->status()];
|
||||
} catch (\Throwable $exception) {
|
||||
$checks[] = ['item' => 'Browserless Reachable', 'status' => 'failed', 'detail' => $exception->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
$this->table(['Item', 'Status', 'Detail'], $checks);
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user