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

4 days ago
<?php
namespace App\Console\Commands;
use App\Services\CompanyNews\NewsCollection;
use Illuminate\Console\Command;
class CollectCompanyNews extends Command
{
1 day ago
protected $signature = 'qcc:collect-news {--limit= : 本轮企业数上限,默认使用批次的每组企业数} {--watch : 常驻等待并处理后台新建批次}';
protected $description = '检查每日自动采集计划,并按组执行企业新闻采集任务';
4 days ago
public function handle(NewsCollection $service): int
{
if ($error = $service->configurationError()) {
$this->error($error);
return self::FAILURE;
}
1 day ago
$limit = $this->option('limit') === null ? null : max(1, min(100, (int) $this->option('limit')));
4 days ago
$count = 0;
do {
try {
1 day ago
$batch = $service->startDue();
if ($batch) $this->info('自动创建批次 #'.$batch->id.',企业数 '.$batch->total);
$count = $service->runGroup($limit);
if ($count) $this->line(now()->toDateTimeString()." 本组已处理 {$count} 个企业任务");
4 days ago
} 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;
}
}