52 lines
1.9 KiB
PHP
52 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\command;
|
|
|
|
use app\common\service\qywx\QywxPromotionAutomationService;
|
|
use think\console\Command;
|
|
use think\console\Input;
|
|
use think\console\Output;
|
|
use think\console\input\Option;
|
|
|
|
/** Supervisor/systemd常驻:只消费欢迎语,不运行慢速客户同步或素材上传。 */
|
|
class QywxWorkPromotionAutomation extends Command
|
|
{
|
|
protected function configure()
|
|
{
|
|
$this->setName('qywx:work-promotion-automation')
|
|
->setDescription('秒级消费推广欢迎语(需常驻;欢迎码仅20秒有效)')
|
|
->addOption('once', null, Option::VALUE_NONE, '只消费一轮');
|
|
}
|
|
|
|
protected function execute(Input $input, Output $output): int
|
|
{
|
|
$running = true;
|
|
if (function_exists('pcntl_async_signals')) {
|
|
pcntl_async_signals(true);
|
|
pcntl_signal(SIGTERM, static function () use (&$running): void { $running = false; });
|
|
pcntl_signal(SIGINT, static function () use (&$running): void { $running = false; });
|
|
}
|
|
$service = new QywxPromotionAutomationService();
|
|
do {
|
|
try {
|
|
$result = $service->processWelcomes(100);
|
|
if ($result['selected'] > 0 || $input->getOption('once')) {
|
|
$output->writeln('QYWX_PROMOTION_WELCOME ' . json_encode($result));
|
|
}
|
|
} catch (\Throwable) {
|
|
// 不输出异常堆栈/SQL/请求,避免把短期凭证带进守护进程日志。
|
|
$output->writeln('QYWX_PROMOTION_WELCOME worker storage unavailable');
|
|
if ($input->getOption('once')) {
|
|
return 1;
|
|
}
|
|
}
|
|
if (!$input->getOption('once') && $running) {
|
|
usleep(250000);
|
|
}
|
|
} while (!$input->getOption('once') && $running);
|
|
return 0;
|
|
}
|
|
}
|