From 547c3eb4887efdce02011d666af6451d78a8fde4 Mon Sep 17 00:00:00 2001 From: Anyon Date: Mon, 2 Dec 2019 11:33:00 +0800 Subject: [PATCH] ComposerUpdate --- composer.lock | 8 +-- vendor/composer/installed.json | 8 +-- vendor/services.php | 2 +- .../think-library/src/queue/WorkQueue.php | 59 +++++++++++-------- 4 files changed, 44 insertions(+), 33 deletions(-) diff --git a/composer.lock b/composer.lock index eadb91dfa..b34f5da3f 100644 --- a/composer.lock +++ b/composer.lock @@ -783,12 +783,12 @@ "source": { "type": "git", "url": "https://github.com/zoujingli/ThinkLibrary.git", - "reference": "82a60f7d4b2362e27318e696a231a124e5c2c793" + "reference": "9e3ecc257550a11f7bdffa7a1c6c6488e7b1453f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/82a60f7d4b2362e27318e696a231a124e5c2c793", - "reference": "82a60f7d4b2362e27318e696a231a124e5c2c793", + "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/9e3ecc257550a11f7bdffa7a1c6c6488e7b1453f", + "reference": "9e3ecc257550a11f7bdffa7a1c6c6488e7b1453f", "shasum": "", "mirrors": [ { @@ -832,7 +832,7 @@ ], "description": "ThinkPHP v6.0 Development Library", "homepage": "http://framework.thinkadmin.top", - "time": "2019-12-02T02:46:31+00:00" + "time": "2019-12-02T03:28:58+00:00" } ], "packages-dev": [], diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 52fdc8042..150fda150 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -805,12 +805,12 @@ "source": { "type": "git", "url": "https://github.com/zoujingli/ThinkLibrary.git", - "reference": "82a60f7d4b2362e27318e696a231a124e5c2c793" + "reference": "9e3ecc257550a11f7bdffa7a1c6c6488e7b1453f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/82a60f7d4b2362e27318e696a231a124e5c2c793", - "reference": "82a60f7d4b2362e27318e696a231a124e5c2c793", + "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/9e3ecc257550a11f7bdffa7a1c6c6488e7b1453f", + "reference": "9e3ecc257550a11f7bdffa7a1c6c6488e7b1453f", "shasum": "", "mirrors": [ { @@ -826,7 +826,7 @@ "ext-json": "*", "topthink/framework": "^6.0" }, - "time": "2019-12-02T02:46:31+00:00", + "time": "2019-12-02T03:28:58+00:00", "type": "library", "extra": { "think": { diff --git a/vendor/services.php b/vendor/services.php index fe0915a3f..c68fe61e1 100644 --- a/vendor/services.php +++ b/vendor/services.php @@ -1,5 +1,5 @@ 'think\\app\\Service', diff --git a/vendor/zoujingli/think-library/src/queue/WorkQueue.php b/vendor/zoujingli/think-library/src/queue/WorkQueue.php index e2c738a46..c4a02b24b 100644 --- a/vendor/zoujingli/think-library/src/queue/WorkQueue.php +++ b/vendor/zoujingli/think-library/src/queue/WorkQueue.php @@ -60,34 +60,45 @@ class WorkQueue extends Command */ protected function execute(Input $input, Output $output) { - try { - set_time_limit(0); - $this->code = trim($input->getArgument('code')); - if (empty($this->code)) throw new Exception("执行任务需要指定任务编号!"); + set_time_limit(0); + $this->code = trim($input->getArgument('code')); + if (empty($this->code)) { + $this->output->error('执行任务需要指定任务编号!'); + } else try { $queue = $this->app->db->name('SystemQueue')->where(['code' => $this->code, 'status' => '1'])->find(); - if (empty($queue)) throw new Exception("执行任务{$this->code}的信息或状态异常!"); - // 锁定任务状态 - $this->app->db->name('SystemQueue')->where(['code' => $this->code])->update([ - 'status' => '2', 'enter_time' => time(), 'exec_desc' => '', 'attempts' => $this->app->db->raw('attempts+1'), - ]); - // 设置进程标题 - if (($process = ProcessService::instance())->iswin()) { - $this->setProcessTitle("ThinkAdmin {$process->version()} 执行任务 - {$queue['title']}"); - } - // 执行任务内容 - if (class_exists($command = $queue['command'])) { - if ($command instanceof QueueService) { - $data = json_decode($queue['data'], true) ?: []; - $this->update('3', $command::instance()->initialize($this->code)->execute($data)); - } else { - throw new Exception("任务处理类 {$command} 未继承 think\\admin\\service\\QueueService"); - } + if (empty($queue)) { + // 这里不做任何处理(该任务可能在其它地方已经在执行) + $this->output->warning($message = "执行任务{$this->code}的或状态异常!"); } else { - $attr = explode(' ', trim(preg_replace('|\s+|', ' ', $queue['command']))); - $this->update('3', $this->app->console->call(array_shift($attr), $attr, 'console')); + // 锁定任务状态 + $this->app->db->name('SystemQueue')->where(['code' => $this->code])->update([ + 'status' => '2', 'enter_time' => time(), 'exec_desc' => '', 'attempts' => $this->app->db->raw('attempts+1'), + ]); + // 设置进程标题 + if (($process = ProcessService::instance())->iswin()) { + $this->setProcessTitle("ThinkAdmin {$process->version()} 执行任务 - {$queue['title']}"); + } + // 执行任务内容 + if (class_exists($command = $queue['command'])) { + // 自定义服务,支持返回消息(支持异常结束,异常码可选择 3|4 设置任务状态) + if ($command instanceof QueueService) { + $data = json_decode($queue['data'], true) ?: []; + $this->update('3', $command::instance()->initialize($this->code)->execute($data)); + } else { + throw new Exception("任务处理类 {$command} 未继承 think\\admin\\service\\QueueService"); + } + } else { + // 自定义指令,不支持返回消息(支持异常结束,异常码可选择 3|4 设置任务状态) + $attr = explode(' ', trim(preg_replace('|\s+|', ' ', $queue['command']))); + $this->update('3', $this->app->console->call(array_shift($attr), $attr, 'console')); + } } } catch (\Exception $e) { - $this->update('4', $e->getMessage()); + if (in_array($e->getCode(), ['3', '4'])) { + $this->update($e->getCode(), $e->getMessage()); + } else { + $this->update('4', $e->getMessage()); + } } }