queue->message($total, $count, $message, $backline); return $this; } /** * 初始化指令变量. * @return $this * @throws Exception */ protected function initialize(Input $input, Output $output): Command { $this->queue = QueueService::instance(); $this->process = ProcessService::instance(); if (defined('WorkQueueCode') && $this->queue->code !== WorkQueueCode) { $this->queue->initialize(WorkQueueCode); } return $this; } /** * 设置失败消息并结束进程. * @param string $message 消息内容 * @throws Exception */ protected function setQueueError(string $message) { if (defined('WorkQueueCode')) { $this->queue->error($message); } else { $this->process->message($message); exit(0); } } /** * 设置成功消息并结束进程. * @param string $message 消息内容 * @throws Exception */ protected function setQueueSuccess(string $message) { if (defined('WorkQueueCode')) { $this->queue->success($message); } else { $this->process->message($message); exit(0); } } /** * 设置进度消息并继续执行. * @param null|string $message 进度消息 * @param null|string $progress 进度数值 * @param int $backline 回退行数 * @return static * @throws Exception */ protected function setQueueProgress(?string $message = null, ?string $progress = null, int $backline = 0): Command { if (defined('WorkQueueCode')) { $this->queue->progress(2, $message, $progress, $backline); } elseif (is_string($message)) { $this->process->message($message, $backline); } return $this; } }