From 8c6e29c7cd59c69312860406b7a776231c2010ec Mon Sep 17 00:00:00 2001 From: Anyon Date: Sat, 2 May 2020 09:43:07 +0800 Subject: [PATCH] ComposerUpdate --- composer.lock | 8 ++-- vendor/composer/installed.json | 8 ++-- vendor/services.php | 2 +- .../think-library/src/command/Queue.php | 21 --------- .../src/command/queue/ListenQueue.php | 12 +++++ .../src/command/queue/WorkQueue.php | 44 +++++++------------ .../src/service/QueueService.php | 21 +++------ 7 files changed, 42 insertions(+), 74 deletions(-) diff --git a/composer.lock b/composer.lock index f14dfc2e7..b76350388 100644 --- a/composer.lock +++ b/composer.lock @@ -909,12 +909,12 @@ "source": { "type": "git", "url": "https://github.com/zoujingli/ThinkLibrary.git", - "reference": "646ddaf7017822aabbc9aa7c3e8e4e0aa095c515" + "reference": "bff122f985c71ac8cf37139c6ce6dbba83482df1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/646ddaf7017822aabbc9aa7c3e8e4e0aa095c515", - "reference": "646ddaf7017822aabbc9aa7c3e8e4e0aa095c515", + "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/bff122f985c71ac8cf37139c6ce6dbba83482df1", + "reference": "bff122f985c71ac8cf37139c6ce6dbba83482df1", "shasum": "", "mirrors": [ { @@ -958,7 +958,7 @@ ], "description": "ThinkPHP v6.0 Development Library", "homepage": "http://framework.thinkadmin.top", - "time": "2020-05-01T12:57:12+00:00" + "time": "2020-05-02T01:35:55+00:00" }, { "name": "zoujingli/wechat-developer", diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 48affefbc..cb54a24a0 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -935,12 +935,12 @@ "source": { "type": "git", "url": "https://github.com/zoujingli/ThinkLibrary.git", - "reference": "646ddaf7017822aabbc9aa7c3e8e4e0aa095c515" + "reference": "bff122f985c71ac8cf37139c6ce6dbba83482df1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/646ddaf7017822aabbc9aa7c3e8e4e0aa095c515", - "reference": "646ddaf7017822aabbc9aa7c3e8e4e0aa095c515", + "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/bff122f985c71ac8cf37139c6ce6dbba83482df1", + "reference": "bff122f985c71ac8cf37139c6ce6dbba83482df1", "shasum": "", "mirrors": [ { @@ -956,7 +956,7 @@ "ext-json": "*", "topthink/framework": "^6.0" }, - "time": "2020-05-01T12:57:12+00:00", + "time": "2020-05-02T01:35:55+00:00", "type": "library", "extra": { "think": { diff --git a/vendor/services.php b/vendor/services.php index 040077346..77a6c5a03 100644 --- a/vendor/services.php +++ b/vendor/services.php @@ -1,5 +1,5 @@ 'think\\app\\Service', diff --git a/vendor/zoujingli/think-library/src/command/Queue.php b/vendor/zoujingli/think-library/src/command/Queue.php index 2e8d3cc57..4c7f82f48 100644 --- a/vendor/zoujingli/think-library/src/command/Queue.php +++ b/vendor/zoujingli/think-library/src/command/Queue.php @@ -15,11 +15,7 @@ namespace think\admin\command; -use Psr\Log\NullLogger; use think\admin\Command; -use think\admin\service\ProcessService; -use think\console\Input; -use think\console\Output; /** * 系统任务基类 @@ -33,21 +29,4 @@ abstract class Queue extends Command * @var string */ protected $table = 'SystemQueue'; - - /** - * 进程服务对象 - * @var ProcessService - */ - protected $process; - - /** - * 任务指令初始化 - * @param Input $input - * @param Output $output - */ - protected function initialize(Input $input, Output $output) - { - $this->app->db->setLog(new NullLogger()); - $this->process = ProcessService::instance(); - } } \ No newline at end of file diff --git a/vendor/zoujingli/think-library/src/command/queue/ListenQueue.php b/vendor/zoujingli/think-library/src/command/queue/ListenQueue.php index 7c3116132..6d3f7c617 100644 --- a/vendor/zoujingli/think-library/src/command/queue/ListenQueue.php +++ b/vendor/zoujingli/think-library/src/command/queue/ListenQueue.php @@ -15,6 +15,7 @@ namespace think\admin\command\queue; +use Psr\Log\NullLogger; use think\admin\command\Queue; use think\Collection; use think\console\Input; @@ -35,6 +36,17 @@ class ListenQueue extends Queue $this->setName('xtask:listen')->setDescription('Start task listening main process'); } + /** + * 初始化任务监听指令 + * @param Input $input + * @param Output $output + */ + protected function initialize(Input $input, Output $output) + { + parent::initialize($input, $output); + $this->app->db->setLog(new NullLogger()); + } + /** * 启动进程守护监听 * @param Input $input 输入对象 diff --git a/vendor/zoujingli/think-library/src/command/queue/WorkQueue.php b/vendor/zoujingli/think-library/src/command/queue/WorkQueue.php index 09433ee7e..68876dc0e 100644 --- a/vendor/zoujingli/think-library/src/command/queue/WorkQueue.php +++ b/vendor/zoujingli/think-library/src/command/queue/WorkQueue.php @@ -28,25 +28,12 @@ use think\console\Output; */ class WorkQueue extends Queue { - /** - * 当前任务编号 + * 执行任务编号 * @var string */ protected $code; - /** - * 当前任务数据 - * @var array - */ - protected $queue; - - /** - * 当前任务服务 - * @var QueueService - */ - protected $qService; - /** * 配置指定信息 */ @@ -70,35 +57,34 @@ class WorkQueue extends Queue if (empty($this->code)) { $this->output->error('Task number needs to be specified for task execution'); } else try { - $this->queue = $this->app->db->name($this->table)->where(['code' => $this->code, 'status' => '1'])->find(); - $this->qService = QueueService::instance()->initialize($this->code); - if (empty($this->queue)) { + $this->queue->initialize($this->code); + if (empty($this->queue->record) || intval($this->queue->record['status']) !== 1) { // 这里不做任何处理(该任务可能在其它地方已经在执行) $this->output->warning($message = "The or status of task {$this->code} is abnormal"); } else { - // 锁定任务状态 + // 锁定任务状态,防止任务再次被执行 $this->app->db->name($this->table)->strict(false)->where(['code' => $this->code])->update([ 'enter_time' => microtime(true), 'attempts' => $this->app->db->raw('attempts+1'), 'outer_time' => '0', 'exec_pid' => getmypid(), 'exec_desc' => '', 'status' => '2', ]); - $this->qService->progress(2, '>>> 任务处理开始 <<<', 0); + $this->queue->progress(2, '>>> 任务处理开始 <<<', 0); // 设置进程标题 if ($this->process->iswin()) { - $this->setProcessTitle("ThinkAdmin {$this->process->version()} Queue - {$this->queue['title']}"); + $this->setProcessTitle("ThinkAdmin {$this->process->version()} Queue - {$this->queue->title}"); } // 执行任务内容 defined('WorkQueueCall') or define('WorkQueueCall', true); defined('WorkQueueCode') or define('WorkQueueCode', $this->code); - if (class_exists($command = $this->queue['command'])) { + if (class_exists($command = $this->queue->record['command'])) { // 自定义服务,支持返回消息(支持异常结束,异常码可选择 3|4 设置任务状态) if (method_exists($command, 'instance') && ($class = $command::instance()) instanceof QueueService) { - $this->update('3', $class->initialize($this->code)->execute(json_decode($this->queue['exec_data'], true) ?: [])); + $this->update('3', $class->initialize($this->code)->execute($this->queue->data)); } else { throw new \think\admin\Exception("自定义 {$command} 未继承 QueueService"); } } else { // 自定义指令,不支持返回消息(支持异常结束,异常码可选择 3|4 设置任务状态) - $attr = explode(' ', trim(preg_replace('|\s+|', ' ', $this->queue['command']))); + $attr = explode(' ', trim(preg_replace('|\s+|', ' ', $this->queue->record['command']))); $this->update('3', $this->app->console->call(array_shift($attr), $attr)->fetch(), false); } } @@ -127,19 +113,19 @@ class WorkQueue extends Queue $this->output->writeln(is_string($message) ? $message : ''); // 任务进度标记 if (!empty($desc[0])) { - $this->qService->progress($status, ">>> {$desc[0]} <<<"); + $this->queue->progress($status, ">>> {$desc[0]} <<<"); } if ($status == 3) { - $this->qService->progress($status, '>>> 任务处理完成 <<<', 100); + $this->queue->progress($status, '>>> 任务处理完成 <<<', 100); } elseif ($status == 4) { - $this->qService->progress($status, '>>> 任务处理失败 <<<'); + $this->queue->progress($status, '>>> 任务处理失败 <<<'); } // 注册循环任务 - if (isset($this->queue['loops_time']) && $this->queue['loops_time'] > 0) { + if (isset($this->queue->record['loops_time']) && $this->queue->record['loops_time'] > 0) { try { - $this->qService->initialize($this->code)->reset($this->queue['loops_time']); + $this->queue->initialize($this->code)->reset($this->queue->record['loops_time']); } catch (\Exception|\Error $exception) { - $this->app->log->error("Queue {$this->queue['code']} Loops Failed. {$exception->getMessage()}"); + $this->app->log->error("Queue {$this->queue->record['code']} Loops Failed. {$exception->getMessage()}"); } } } diff --git a/vendor/zoujingli/think-library/src/service/QueueService.php b/vendor/zoujingli/think-library/src/service/QueueService.php index a2bdcf53f..febdc3021 100644 --- a/vendor/zoujingli/think-library/src/service/QueueService.php +++ b/vendor/zoujingli/think-library/src/service/QueueService.php @@ -48,7 +48,7 @@ class QueueService extends Service * 当前任务数据 * @var array */ - public $queue = []; + public $record = []; /** * 数据初始化 @@ -63,26 +63,17 @@ class QueueService extends Service { if (!empty($code)) { $this->code = $code; - $this->queue = $this->app->db->name('SystemQueue')->where(['code' => $this->code])->find(); - if (empty($this->queue)) { + $this->record = $this->app->db->name('SystemQueue')->where(['code' => $this->code])->find(); + if (empty($this->record)) { $this->app->log->error("Qeueu initialize failed, Queue {$code} not found."); throw new \think\admin\Exception("Qeueu initialize failed, Queue {$code} not found."); } - list($this->code, $this->title) = [$this->queue['code'], $this->queue['title']]; - $this->data = json_decode($this->queue['exec_data'], true) ?: []; + [$this->code, $this->title] = [$this->record['code'], $this->record['title']]; + $this->data = json_decode($this->record['exec_data'], true) ?: []; } return $this; } - /** - * 判断是否WIN环境 - * @return boolean - */ - protected function iswin() - { - return ProcessService::instance()->iswin(); - } - /** * 重发异步任务 * @param integer $wait 等待时间 @@ -94,7 +85,7 @@ class QueueService extends Service */ public function reset($wait = 0) { - if (empty($this->queue)) { + if (empty($this->record)) { $this->app->log->error("Qeueu reset failed, Queue {$this->code} data cannot be empty!"); throw new \think\admin\Exception("Qeueu reset failed, Queue {$this->code} data cannot be empty!"); }