You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.5 KiB
39 lines
1.5 KiB
<?php
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\CompanyNews\NewsCollection;
|
|
use Illuminate\Console\Command;
|
|
|
|
class CollectCompanyNews extends Command
|
|
{
|
|
protected $signature = 'qcc:collect-news {--limit= : 本轮企业数上限,默认使用批次的每组企业数} {--watch : 常驻等待并处理后台新建批次}';
|
|
protected $description = '检查每日自动采集计划,并按组执行企业新闻采集任务';
|
|
|
|
public function handle(NewsCollection $service): int
|
|
{
|
|
if ($error = $service->configurationError()) {
|
|
$this->error($error);
|
|
return self::FAILURE;
|
|
}
|
|
$limit = $this->option('limit') === null ? null : max(1, min(100, (int) $this->option('limit')));
|
|
$count = 0;
|
|
do {
|
|
try {
|
|
$batch = $service->startDue();
|
|
if ($batch) $this->info('自动创建批次 #'.$batch->id.',企业数 '.$batch->total);
|
|
$count = $service->runGroup($limit);
|
|
if ($count) $this->line(now()->toDateTimeString()." 本组已处理 {$count} 个企业任务");
|
|
} catch (\Throwable $e) {
|
|
if (!$this->option('watch')) throw $e;
|
|
report($e);
|
|
$this->error('采集暂时中断,将重试检查任务:'.$e->getMessage());
|
|
}
|
|
if (!$this->option('watch')) break;
|
|
$count = 0;
|
|
sleep(5);
|
|
} while (true);
|
|
$this->info("本次已处理 {$count} 个企业任务");
|
|
return self::SUCCESS;
|
|
}
|
|
}
|