diff --git a/app/wechat/command/Fans.php b/app/wechat/command/Fans.php index 6c66ea4a9..1380d03ad 100644 --- a/app/wechat/command/Fans.php +++ b/app/wechat/command/Fans.php @@ -56,7 +56,7 @@ class Fans extends Command $message .= $this->$method(); } } - $this->setQueueMessage(3, $message); + $this->setQueueSuccess($message); } /** @@ -82,7 +82,7 @@ class Fans extends Command foreach ($list['user_info_list'] as $user) { $string = str_pad(++$done, strlen($result['total']), '0', STR_PAD_LEFT); $message = "({$string}/{$result['total']}) -> {$user['openid']} {$user['nickname']}"; - $this->setQueueProgress(2, $message, $done * 100 / $result['total']); + $this->setQueueProgress($message, $done * 100 / $result['total']); FansService::instance()->set($user, $appid); } } @@ -115,7 +115,7 @@ class Fans extends Command foreach (array_chunk($result['data']['openid'], 100) as $chunk) { $this->app->db->name('WechatFans')->where(['is_black' => '0'])->whereIn('openid', $chunk)->update(['is_black' => '1']); } - $this->setQueueProgress(2, "共计同步微信黑名单{$result['total']}人"); + $this->setQueueProgress("共计同步微信黑名单{$result['total']}人"); $next = $result['total'] > $done ? $result['next_openid'] : null; } $this->output->comment('--> Wechat blacklist data synchronization completed'); @@ -148,7 +148,7 @@ class Fans extends Command foreach ($list['tags'] as &$tag) { $tag['appid'] = $appid; $progress = str_pad(++$index, strlen($count), '0', STR_PAD_LEFT); - $this->setQueueProgress(2, "({$progress}/{$count}) -> {$tag['name']}"); + $this->setQueueProgress("({$progress}/{$count}) -> {$tag['name']}"); } $this->app->db->name('WechatFansTags')->where(['appid' => $appid])->delete(); $this->app->db->name('WechatFansTags')->insertAll($list['tags']); diff --git a/composer.lock b/composer.lock index b76350388..9816362e1 100644 --- a/composer.lock +++ b/composer.lock @@ -909,12 +909,12 @@ "source": { "type": "git", "url": "https://github.com/zoujingli/ThinkLibrary.git", - "reference": "bff122f985c71ac8cf37139c6ce6dbba83482df1" + "reference": "0dfd6270436823d9a2173532ad21ef0126bcb863" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/bff122f985c71ac8cf37139c6ce6dbba83482df1", - "reference": "bff122f985c71ac8cf37139c6ce6dbba83482df1", + "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/0dfd6270436823d9a2173532ad21ef0126bcb863", + "reference": "0dfd6270436823d9a2173532ad21ef0126bcb863", "shasum": "", "mirrors": [ { @@ -958,7 +958,7 @@ ], "description": "ThinkPHP v6.0 Development Library", "homepage": "http://framework.thinkadmin.top", - "time": "2020-05-02T01:35:55+00:00" + "time": "2020-05-02T11:46:38+00:00" }, { "name": "zoujingli/wechat-developer", diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index abc0186cc..9264c7e2f 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -252,10 +252,10 @@ return array( 'think\\admin\\Exception' => $vendorDir . '/zoujingli/think-library/src/Exception.php', 'think\\admin\\Helper' => $vendorDir . '/zoujingli/think-library/src/Helper.php', 'think\\admin\\Library' => $vendorDir . '/zoujingli/think-library/src/Library.php', + 'think\\admin\\Queue' => $vendorDir . '/zoujingli/think-library/src/Queue.php', 'think\\admin\\Service' => $vendorDir . '/zoujingli/think-library/src/Service.php', 'think\\admin\\Storage' => $vendorDir . '/zoujingli/think-library/src/Storage.php', 'think\\admin\\command\\Install' => $vendorDir . '/zoujingli/think-library/src/command/Install.php', - 'think\\admin\\command\\Queue' => $vendorDir . '/zoujingli/think-library/src/command/Queue.php', 'think\\admin\\command\\Version' => $vendorDir . '/zoujingli/think-library/src/command/Version.php', 'think\\admin\\command\\database\\Optimize' => $vendorDir . '/zoujingli/think-library/src/command/database/Optimize.php', 'think\\admin\\command\\database\\Repair' => $vendorDir . '/zoujingli/think-library/src/command/database/Repair.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 189159d8e..0b0423f0e 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -385,10 +385,10 @@ class ComposerStaticInitf41e9df38a61a147f539b835fbd021f0 'think\\admin\\Exception' => __DIR__ . '/..' . '/zoujingli/think-library/src/Exception.php', 'think\\admin\\Helper' => __DIR__ . '/..' . '/zoujingli/think-library/src/Helper.php', 'think\\admin\\Library' => __DIR__ . '/..' . '/zoujingli/think-library/src/Library.php', + 'think\\admin\\Queue' => __DIR__ . '/..' . '/zoujingli/think-library/src/Queue.php', 'think\\admin\\Service' => __DIR__ . '/..' . '/zoujingli/think-library/src/Service.php', 'think\\admin\\Storage' => __DIR__ . '/..' . '/zoujingli/think-library/src/Storage.php', 'think\\admin\\command\\Install' => __DIR__ . '/..' . '/zoujingli/think-library/src/command/Install.php', - 'think\\admin\\command\\Queue' => __DIR__ . '/..' . '/zoujingli/think-library/src/command/Queue.php', 'think\\admin\\command\\Version' => __DIR__ . '/..' . '/zoujingli/think-library/src/command/Version.php', 'think\\admin\\command\\database\\Optimize' => __DIR__ . '/..' . '/zoujingli/think-library/src/command/database/Optimize.php', 'think\\admin\\command\\database\\Repair' => __DIR__ . '/..' . '/zoujingli/think-library/src/command/database/Repair.php', diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index cb54a24a0..d4a2cf993 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": "bff122f985c71ac8cf37139c6ce6dbba83482df1" + "reference": "0dfd6270436823d9a2173532ad21ef0126bcb863" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/bff122f985c71ac8cf37139c6ce6dbba83482df1", - "reference": "bff122f985c71ac8cf37139c6ce6dbba83482df1", + "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/0dfd6270436823d9a2173532ad21ef0126bcb863", + "reference": "0dfd6270436823d9a2173532ad21ef0126bcb863", "shasum": "", "mirrors": [ { @@ -956,7 +956,7 @@ "ext-json": "*", "topthink/framework": "^6.0" }, - "time": "2020-05-02T01:35:55+00:00", + "time": "2020-05-02T11:46:38+00:00", "type": "library", "extra": { "think": { diff --git a/vendor/services.php b/vendor/services.php index 77a6c5a03..599bab84d 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.php b/vendor/zoujingli/think-library/src/Command.php index 1195be61d..66890ef28 100644 --- a/vendor/zoujingli/think-library/src/Command.php +++ b/vendor/zoujingli/think-library/src/Command.php @@ -53,7 +53,6 @@ class Command extends ThinkCommand /** * 设置当前任务进度 - * @param null|integer $status 任务状态 * @param null|string $message 进度消息 * @param null|integer $progress 进度数值 * @return Command @@ -62,7 +61,7 @@ class Command extends ThinkCommand * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - protected function setQueueProgress($status = null, $message = null, $progress = null) + protected function setQueueProgress($message = null, $progress = null) { if (defined('WorkQueueCode')) { if (!$this->queue instanceof QueueService) { @@ -71,24 +70,7 @@ class Command extends ThinkCommand if ($this->queue->code !== WorkQueueCode) { $this->queue->initialize(WorkQueueCode); } - $this->queue->progress($status, $message, $progress); - } elseif (is_string($message)) { - $this->output->writeln($message); - } - return $this; - } - - /** - * 结束任务并设置状态消息 - * @param integer $status 任务状态 - * @param string $message 消息内容 - * @return Command - * @throws Exception - */ - protected function setQueueMessage($status, $message) - { - if (defined('WorkQueueCode')) { - throw new Exception($message, $status, WorkQueueCode); + $this->queue->progress(2, $message, $progress); } elseif (is_string($message)) { $this->output->writeln($message); } @@ -101,9 +83,14 @@ class Command extends ThinkCommand * @return Command * @throws Exception */ - protected function setQueueSuccessMessage($message) + protected function setQueueSuccess($message) { - return $this->setQueueMessage(3, $message); + if (defined('WorkQueueCode')) { + throw new Exception($message, 3, WorkQueueCode); + } elseif (is_string($message)) { + $this->output->writeln($message); + } + return $this; } /** @@ -112,9 +99,14 @@ class Command extends ThinkCommand * @return Command * @throws Exception */ - protected function setQueueErrorMessage($message) + protected function setQueueError($message) { - return $this->setQueueMessage(4, $message); + if (defined('WorkQueueCode')) { + throw new Exception($message, 4, WorkQueueCode); + } elseif (is_string($message)) { + $this->output->writeln($message); + } + return $this; } } \ No newline at end of file diff --git a/vendor/zoujingli/think-library/src/Queue.php b/vendor/zoujingli/think-library/src/Queue.php new file mode 100644 index 000000000..6449c340d --- /dev/null +++ b/vendor/zoujingli/think-library/src/Queue.php @@ -0,0 +1,107 @@ +app = $app; + $this->process = $process; + } + + /** + * 初始化任务数据 + * @param QueueService $queue + * @return $this + */ + public function initialize(QueueService $queue) + { + $this->queue = $queue; + return $this; + } + + /** + * 执行任务处理内容 + * @param array $data + * @return mixed + */ + abstract public function execute(array $data = []); + + /** + * 设置任务的进度 + * @param null|string $message 进度消息 + * @param null|integer $progress 进度数值 + * @return Queue + */ + protected function setQueueProgress($message = null, $progress = null) + { + $this->queue->progress(2, $message, $progress); + return $this; + } + + /** + * 设置成功的消息 + * @param string $message 消息内容 + * @throws Exception + */ + protected function setQueueSuccess($message) + { + throw new Exception($message, 3, $this->queue->code); + } + + /** + * 设置失败的消息 + * @param string $message 消息内容 + * @throws Exception + */ + protected function setQueueError($message) + { + throw new Exception($message, 4, $this->queue->code); + } +} \ No newline at end of file diff --git a/vendor/zoujingli/think-library/src/command/Queue.php b/vendor/zoujingli/think-library/src/command/Queue.php deleted file mode 100644 index 4c7f82f48..000000000 --- a/vendor/zoujingli/think-library/src/command/Queue.php +++ /dev/null @@ -1,32 +0,0 @@ -setQueueProgress(2, "正在获取需要优化的数据表", 0); + $this->setQueueProgress("正在获取需要优化的数据表", 0); foreach ($this->app->db->query("show tables") as $item) { $tables = array_merge($tables, array_values($item)); } - list($total, $used) = [count($tables), 0]; - $this->setQueueProgress(2, "总共需要优化 {$total} 张数据表", 0); + [$total, $used] = [count($tables), 0]; + $this->setQueueProgress("总共需要优化 {$total} 张数据表", 0); foreach ($tables as $table) { $stridx = str_pad(++$used, strlen("{$total}"), '0', STR_PAD_LEFT) . "/{$total}"; - $this->setQueueProgress(2, "[{$stridx}] 正在优化数据表 {$table}", $used / $total * 100); + $this->setQueueProgress("[{$stridx}] 正在优化数据表 {$table}", $used / $total * 100); $this->app->db->query("OPTIMIZE TABLE `{$table}`"); } } diff --git a/vendor/zoujingli/think-library/src/command/database/Repair.php b/vendor/zoujingli/think-library/src/command/database/Repair.php index dc111d1ea..98e964a99 100644 --- a/vendor/zoujingli/think-library/src/command/database/Repair.php +++ b/vendor/zoujingli/think-library/src/command/database/Repair.php @@ -43,15 +43,15 @@ class Repair extends Command protected function execute(Input $input, Output $output) { $tables = []; - $this->setQueueProgress(2, "正在获取需要修复的数据表", 0); + $this->setQueueProgress("正在获取需要修复的数据表", 0); foreach ($this->app->db->query("show tables") as $item) { $tables = array_merge($tables, array_values($item)); } - list($total, $used) = [count($tables), 0]; - $this->setQueueProgress(2, "总共需要修复 {$total} 张数据表", 0); + [$total, $used] = [count($tables), 0]; + $this->setQueueProgress("总共需要修复 {$total} 张数据表", 0); foreach ($tables as $table) { $stridx = str_pad(++$used, strlen("{$total}"), '0', STR_PAD_LEFT) . "/{$total}"; - $this->setQueueProgress(2, "[{$stridx}] 正在修复数据表 {$table}", $used / $total * 100); + $this->setQueueProgress("[{$stridx}] 正在修复数据表 {$table}", $used / $total * 100); $this->app->db->query("REPAIR TABLE `{$table}`"); } } diff --git a/vendor/zoujingli/think-library/src/command/queue/CleanQueue.php b/vendor/zoujingli/think-library/src/command/queue/CleanQueue.php index 2a8067358..cad7454f6 100644 --- a/vendor/zoujingli/think-library/src/command/queue/CleanQueue.php +++ b/vendor/zoujingli/think-library/src/command/queue/CleanQueue.php @@ -15,7 +15,7 @@ namespace think\admin\command\queue; -use think\admin\command\Queue; +use think\admin\Command; use think\console\Input; use think\console\input\Argument; use think\console\Output; @@ -25,7 +25,7 @@ use think\console\Output; * Class CleanQueue * @package think\admin\command\queue */ -class CleanQueue extends Queue +class CleanQueue extends Command { /** * 截止时间 @@ -33,6 +33,12 @@ class CleanQueue extends Queue */ protected $time; + /** + * 绑定数据表 + * @var string + */ + protected $table = 'SystemQueue'; + /** * 配置指定信息 */ @@ -55,17 +61,17 @@ class CleanQueue extends Queue { $this->time = $input->getArgument('time'); if (empty($this->time) || !is_numeric($this->time) || $this->time <= 0) { - $this->setQueueMessage(4, "参数错误,需要传入任务超时时间"); + $this->setQueueError("参数错误,需要传入任务超时时间"); } else { $map = [['exec_time', '<', time() - $this->time]]; $count1 = $this->app->db->name($this->table)->where($map)->delete(); - $this->setQueueProgress(2, "清理 {$count1} 条历史任务成功", 50); + $this->setQueueProgress("清理 {$count1} 条历史任务成功", 50); // 重置超60分钟无响应的记录 $map = [['exec_time', '<', time() - 3600], ['status', '=', '2']]; $count2 = $this->app->db->name($this->table)->where($map)->update([ 'status' => '4', 'exec_desc' => '任务执行超时,已自动标识为失败!', ]); - $this->setQueueProgress(2, "处理 {$count2} 条超时间任务成功", 100); + $this->setQueueProgress("处理 {$count2} 条超时间任务成功", 100); } } } \ 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 6d3f7c617..11b7e5c23 100644 --- a/vendor/zoujingli/think-library/src/command/queue/ListenQueue.php +++ b/vendor/zoujingli/think-library/src/command/queue/ListenQueue.php @@ -16,7 +16,7 @@ namespace think\admin\command\queue; use Psr\Log\NullLogger; -use think\admin\command\Queue; +use think\admin\Command; use think\Collection; use think\console\Input; use think\console\Output; @@ -26,8 +26,14 @@ use think\console\Output; * Class ListenQueue * @package think\admin\command\queue */ -class ListenQueue extends Queue +class ListenQueue extends Command { + /** + * 绑定数据表 + * @var string + */ + protected $table = 'SystemQueue'; + /** * 配置指定信息 */ diff --git a/vendor/zoujingli/think-library/src/command/queue/QueryQueue.php b/vendor/zoujingli/think-library/src/command/queue/QueryQueue.php index f0452c5b2..150670075 100644 --- a/vendor/zoujingli/think-library/src/command/queue/QueryQueue.php +++ b/vendor/zoujingli/think-library/src/command/queue/QueryQueue.php @@ -15,7 +15,7 @@ namespace think\admin\command\queue; -use think\admin\command\Queue; +use think\admin\Command; use think\console\Input; use think\console\Output; @@ -24,7 +24,7 @@ use think\console\Output; * Class QueryQueue * @package think\admin\command\queue */ -class QueryQueue extends Queue +class QueryQueue extends Command { /** * 指令属性配置 diff --git a/vendor/zoujingli/think-library/src/command/queue/StartQueue.php b/vendor/zoujingli/think-library/src/command/queue/StartQueue.php index d7a2dee17..cc46d4523 100644 --- a/vendor/zoujingli/think-library/src/command/queue/StartQueue.php +++ b/vendor/zoujingli/think-library/src/command/queue/StartQueue.php @@ -15,7 +15,7 @@ namespace think\admin\command\queue; -use think\admin\command\Queue; +use think\admin\Command; use think\console\Input; use think\console\Output; @@ -24,8 +24,13 @@ use think\console\Output; * Class StartQueue * @package think\admin\command\queue */ -class StartQueue extends Queue +class StartQueue extends Command { + /** + * 绑定数据表 + * @var string + */ + protected $table = 'SystemQueue'; /** * 指令属性配置 diff --git a/vendor/zoujingli/think-library/src/command/queue/StateQueue.php b/vendor/zoujingli/think-library/src/command/queue/StateQueue.php index bcf98c76d..614ab8d98 100644 --- a/vendor/zoujingli/think-library/src/command/queue/StateQueue.php +++ b/vendor/zoujingli/think-library/src/command/queue/StateQueue.php @@ -15,7 +15,7 @@ namespace think\admin\command\queue; -use think\admin\command\Queue; +use think\admin\Command; use think\console\Input; use think\console\Output; @@ -24,7 +24,7 @@ use think\console\Output; * Class StateQueue * @package think\admin\command\queue */ -class StateQueue extends Queue +class StateQueue extends Command { /** * 指令属性配置 diff --git a/vendor/zoujingli/think-library/src/command/queue/StopQueue.php b/vendor/zoujingli/think-library/src/command/queue/StopQueue.php index f197073ec..4a97e4cd7 100644 --- a/vendor/zoujingli/think-library/src/command/queue/StopQueue.php +++ b/vendor/zoujingli/think-library/src/command/queue/StopQueue.php @@ -15,7 +15,7 @@ namespace think\admin\command\queue; -use think\admin\command\Queue; +use think\admin\Command; use think\console\Input; use think\console\Output; @@ -24,7 +24,7 @@ use think\console\Output; * Class StopQueue * @package think\admin\command\queue */ -class StopQueue extends Queue +class StopQueue extends Command { /** diff --git a/vendor/zoujingli/think-library/src/command/queue/WorkQueue.php b/vendor/zoujingli/think-library/src/command/queue/WorkQueue.php index 68876dc0e..2cb3ec862 100644 --- a/vendor/zoujingli/think-library/src/command/queue/WorkQueue.php +++ b/vendor/zoujingli/think-library/src/command/queue/WorkQueue.php @@ -15,8 +15,7 @@ namespace think\admin\command\queue; -use think\admin\command\Queue; -use think\admin\service\QueueService; +use think\admin\Command; use think\console\Input; use think\console\input\Argument; use think\console\Output; @@ -26,7 +25,7 @@ use think\console\Output; * Class WorkQueue * @package think\admin\command\queue */ -class WorkQueue extends Queue +class WorkQueue extends Command { /** * 执行任务编号 @@ -35,7 +34,13 @@ class WorkQueue extends Queue protected $code; /** - * 配置指定信息 + * 绑定数据表 + * @var string + */ + protected $table = 'SystemQueue'; + + /** + * 配置指定参数 */ protected function configure() { @@ -76,16 +81,19 @@ class WorkQueue extends Queue defined('WorkQueueCall') or define('WorkQueueCall', true); defined('WorkQueueCode') or define('WorkQueueCode', $this->code); 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($this->queue->data)); + // 自定义任务,支持返回消息(支持异常结束,异常码可选择 3|4 设置任务状态) + $class = $this->app->make($command, [], true); + if ($class instanceof \think\admin\Queue) { + $this->update(3, $class->initialize($this->queue)->execute($this->queue->data)); + } elseif ($class instanceof \think\admin\service\QueueService) { + $this->update(3, $class->initialize($this->queue->code)->execute($this->queue->data)); } else { - throw new \think\admin\Exception("自定义 {$command} 未继承 QueueService"); + throw new \think\admin\Exception("自定义 {$command} 未继承 Queue 或 QueueService"); } } else { // 自定义指令,不支持返回消息(支持异常结束,异常码可选择 3|4 设置任务状态) $attr = explode(' ', trim(preg_replace('|\s+|', ' ', $this->queue->record['command']))); - $this->update('3', $this->app->console->call(array_shift($attr), $attr)->fetch(), false); + $this->update(3, $this->app->console->call(array_shift($attr), $attr)->fetch(), false); } } } catch (\Exception|\Error $exception) {