50 lines
1.6 KiB
PHP
50 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace app\common\command;
|
|
|
|
use app\common\service\ai\KbRedisQueueService;
|
|
use think\console\Command;
|
|
use think\console\Input;
|
|
use think\console\Output;
|
|
use think\console\input\Option;
|
|
|
|
class KbEnqueueRecent extends Command
|
|
{
|
|
protected function configure()
|
|
{
|
|
$this->setName('kb:enqueue-recent')
|
|
->setDescription('扫描最近更新内容并写入AI知识库Redis队列')
|
|
->addOption('limit', null, Option::VALUE_OPTIONAL, '每个来源最多扫描数量', 1000)
|
|
->addOption('minutes', null, Option::VALUE_OPTIONAL, '扫描最近多少分钟更新的数据', 30);
|
|
}
|
|
|
|
protected function execute(Input $input, Output $output)
|
|
{
|
|
$limit = max(1, (int) $input->getOption('limit'));
|
|
$minutes = max(1, (int) $input->getOption('minutes'));
|
|
$summary = KbRedisQueueService::enqueueRecent($limit, $minutes);
|
|
|
|
foreach ($summary['targets'] as $label => $target) {
|
|
$output->writeln(sprintf(
|
|
'[kb:enqueue-recent] %s scanned=%d queued=%d deduped=%d',
|
|
$label,
|
|
(int) $target['scanned'],
|
|
(int) $target['queued'],
|
|
(int) $target['deduped']
|
|
));
|
|
}
|
|
|
|
$output->writeln(sprintf(
|
|
'[kb:enqueue-recent] stream=%s scanned=%d queued=%d deduped=%d limit=%d minutes=%d',
|
|
$summary['stream'],
|
|
(int) $summary['scanned'],
|
|
(int) $summary['queued'],
|
|
(int) $summary['deduped'],
|
|
(int) $summary['limit'],
|
|
(int) $summary['minutes']
|
|
));
|
|
|
|
return 0;
|
|
}
|
|
}
|