| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace app\admin\command;
- use app\common\library\ps\AiRecognizer;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Option;
- use think\console\Output;
- /**
- * 后台/计划任务执行 AI 识版。
- */
- class Psaijob extends Command
- {
- protected function configure()
- {
- $this->setName('ps:ai-job')
- ->addOption('id', null, Option::VALUE_OPTIONAL, 'job id', 0)
- ->addOption('limit', null, Option::VALUE_OPTIONAL, 'pending batch size', 1)
- ->setDescription('Run AI template recognition jobs');
- }
- protected function execute(Input $input, Output $output)
- {
- $id = (int)$input->getOption('id');
- if ($id > 0) {
- $job = AiRecognizer::run($id);
- $output->writeln('job #' . $id . ' => ' . $job['status']);
- if (!empty($job['error_msg'])) {
- $output->writeln($job['error_msg']);
- }
- return;
- }
- $ids = AiRecognizer::pendingIds((int)$input->getOption('limit'));
- if (!$ids) {
- $output->writeln('no pending jobs');
- return;
- }
- foreach ($ids as $jobId) {
- $job = AiRecognizer::run($jobId);
- $output->writeln('job #' . $jobId . ' => ' . $job['status']);
- if (!empty($job['error_msg'])) {
- $output->writeln($job['error_msg']);
- }
- }
- }
- }
|