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.4 KiB
39 lines
1.4 KiB
|
3 days ago
|
<?php
|
||
|
|
namespace App\Console\Commands;
|
||
|
|
|
||
|
|
use App\Services\CompanyNews\NewsCollection;
|
||
|
|
use Illuminate\Console\Command;
|
||
|
|
|
||
|
|
class CollectCompanyNews extends Command
|
||
|
|
{
|
||
|
|
protected $signature = 'qcc:collect-news {--limit=1000 : 单轮最多处理企业数} {--watch : 常驻等待并处理后台新建批次}';
|
||
|
|
protected $description = '依次执行后台已创建的新闻采集任务,不更改企业户状态';
|
||
|
|
|
||
|
|
public function handle(NewsCollection $service): int
|
||
|
|
{
|
||
|
|
if ($error = $service->configurationError()) {
|
||
|
|
$this->error($error);
|
||
|
|
return self::FAILURE;
|
||
|
|
}
|
||
|
|
$limit = max(1, min(10000, (int) $this->option('limit')));
|
||
|
|
$count = 0;
|
||
|
|
do {
|
||
|
|
try {
|
||
|
|
while ($count < $limit && $service->runOne()) {
|
||
|
|
$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;
|
||
|
|
}
|
||
|
|
}
|