setName('esign:archive-work')->setDescription('补传已签处方 PDF 到私有 COS') ->addOption('limit', null, Option::VALUE_REQUIRED, '最多处理的处方数,1至100', '20'); } protected function execute(Input $input, Output $output): int { try { $ids = PrescriptionEsignArchive::pending(max(1, min(100, (int) $input->getOption('limit')))); } catch (\Throwable) { // 抛出会让 Crontab 把任务置为错误并停止调度,归档补传就永久中断了。 $output->writeln('ESIGN_ARCHIVE_WORK database_unavailable'); return 1; } $archived = 0; foreach ($ids as $id) { $archived += PrescriptionEsignArchive::upload((int) $id) ? 1 : 0; } $output->writeln('ESIGN_ARCHIVE_WORK ' . json_encode(['selected' => count($ids), 'archived' => $archived, 'deferred' => count($ids) - $archived])); return $archived === count($ids) ? 0 : 1; } }