ComposerUpdate

This commit is contained in:
Anyon 2020-05-02 19:53:59 +08:00
parent 8c6e29c7cd
commit 8209384a1b
18 changed files with 195 additions and 103 deletions

View File

@ -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']);

8
composer.lock generated
View File

@ -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",

View File

@ -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',

View File

@ -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',

View File

@ -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": {

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php
// This file is automatically generated at:2020-05-02 09:41:51
// This file is automatically generated at:2020-05-02 19:51:24
declare (strict_types = 1);
return array (
0 => 'think\\app\\Service',

View File

@ -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;
}
}

View File

@ -0,0 +1,107 @@
<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/zoujingli/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/ThinkLibrary
// | github 代码仓库https://github.com/zoujingli/ThinkLibrary
// +----------------------------------------------------------------------
namespace think\admin;
use think\admin\service\ProcessService;
use think\admin\service\QueueService;
use think\App;
/**
* 任务基础类
* Class Queue
* @package think\admin
*/
abstract class Queue
{
/**
* 应用实例
* @var App
*/
protected $app;
/**
* 任务控制服务
* @var QueueService
*/
protected $queue;
/**
* 进程控制服务
* @var ProcessService
*/
protected $process;
/**
* Queue constructor.
* @param App $app
* @param ProcessService $process
*/
public function __construct(App $app, ProcessService $process)
{
$this->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);
}
}

View File

@ -1,32 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/zoujingli/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/ThinkLibrary
// | github 代码仓库https://github.com/zoujingli/ThinkLibrary
// +----------------------------------------------------------------------
namespace think\admin\command;
use think\admin\Command;
/**
* 系统任务基类
* Class Queue
* @package think\admin\command
*/
abstract class Queue extends Command
{
/**
* 绑定数据表
* @var string
*/
protected $table = 'SystemQueue';
}

View File

@ -43,15 +43,15 @@ class Optimize 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("OPTIMIZE TABLE `{$table}`");
}
}

View File

@ -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}`");
}
}

View File

@ -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);
}
}
}

View File

@ -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';
/**
* 配置指定信息
*/

View File

@ -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
{
/**
* 指令属性配置

View File

@ -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';
/**
* 指令属性配置

View File

@ -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
{
/**
* 指令属性配置

View File

@ -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
{
/**

View File

@ -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) {