ComposerUpdate

This commit is contained in:
Anyon 2020-01-10 10:46:41 +08:00
parent 44807f2ae4
commit 1b67dfc0a9
20 changed files with 172 additions and 135 deletions

View File

@ -134,15 +134,17 @@ class Queue extends Controller
/**
* 创建记录清理任务
* @auth true
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function clear()
{
QueueService::instance()->addCleanQueue();
$this->success('创建清理任务成功!');
try {
QueueService::instance()->addCleanQueue();
$this->success('创建清理任务成功!');
} catch (HttpResponseException $exception) {
throw $exception;
} catch (\Exception $exception) {
$this->error($exception->getMessage());
}
}
/**

8
composer.lock generated
View File

@ -909,12 +909,12 @@
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "608e1bd304e8935c19318540ba328625914e2b44"
"reference": "95cfaa9e2e93adf76a4e28f57157d8f779f55680"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/608e1bd304e8935c19318540ba328625914e2b44",
"reference": "608e1bd304e8935c19318540ba328625914e2b44",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/95cfaa9e2e93adf76a4e28f57157d8f779f55680",
"reference": "95cfaa9e2e93adf76a4e28f57157d8f779f55680",
"shasum": "",
"mirrors": [
{
@ -958,7 +958,7 @@
],
"description": "ThinkPHP v6.0 Development Library",
"homepage": "http://framework.thinkadmin.top",
"time": "2020-01-09T07:53:07+00:00"
"time": "2020-01-10T02:43:12+00:00"
},
{
"name": "zoujingli/wechat-developer",

View File

@ -247,7 +247,15 @@ return array(
'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\\queue\\CleanQueue' => $vendorDir . '/zoujingli/think-library/src/command/queue/CleanQueue.php',
'think\\admin\\command\\queue\\ListenQueue' => $vendorDir . '/zoujingli/think-library/src/command/queue/ListenQueue.php',
'think\\admin\\command\\queue\\QueryQueue' => $vendorDir . '/zoujingli/think-library/src/command/queue/QueryQueue.php',
'think\\admin\\command\\queue\\StartQueue' => $vendorDir . '/zoujingli/think-library/src/command/queue/StartQueue.php',
'think\\admin\\command\\queue\\StateQueue' => $vendorDir . '/zoujingli/think-library/src/command/queue/StateQueue.php',
'think\\admin\\command\\queue\\StopQueue' => $vendorDir . '/zoujingli/think-library/src/command/queue/StopQueue.php',
'think\\admin\\command\\queue\\WorkQueue' => $vendorDir . '/zoujingli/think-library/src/command/queue/WorkQueue.php',
'think\\admin\\extend\\CodeExtend' => $vendorDir . '/zoujingli/think-library/src/extend/CodeExtend.php',
'think\\admin\\extend\\DataExtend' => $vendorDir . '/zoujingli/think-library/src/extend/DataExtend.php',
'think\\admin\\extend\\ExcelExtend' => $vendorDir . '/zoujingli/think-library/src/extend/ExcelExtend.php',
@ -259,13 +267,6 @@ return array(
'think\\admin\\helper\\SaveHelper' => $vendorDir . '/zoujingli/think-library/src/helper/SaveHelper.php',
'think\\admin\\helper\\TokenHelper' => $vendorDir . '/zoujingli/think-library/src/helper/TokenHelper.php',
'think\\admin\\helper\\ValidateHelper' => $vendorDir . '/zoujingli/think-library/src/helper/ValidateHelper.php',
'think\\admin\\queue\\CleanQueue' => $vendorDir . '/zoujingli/think-library/src/queue/CleanQueue.php',
'think\\admin\\queue\\ListenQueue' => $vendorDir . '/zoujingli/think-library/src/queue/ListenQueue.php',
'think\\admin\\queue\\QueryQueue' => $vendorDir . '/zoujingli/think-library/src/queue/QueryQueue.php',
'think\\admin\\queue\\StartQueue' => $vendorDir . '/zoujingli/think-library/src/queue/StartQueue.php',
'think\\admin\\queue\\StateQueue' => $vendorDir . '/zoujingli/think-library/src/queue/StateQueue.php',
'think\\admin\\queue\\StopQueue' => $vendorDir . '/zoujingli/think-library/src/queue/StopQueue.php',
'think\\admin\\queue\\WorkQueue' => $vendorDir . '/zoujingli/think-library/src/queue/WorkQueue.php',
'think\\admin\\service\\AdminService' => $vendorDir . '/zoujingli/think-library/src/service/AdminService.php',
'think\\admin\\service\\CaptchaService' => $vendorDir . '/zoujingli/think-library/src/service/CaptchaService.php',
'think\\admin\\service\\ExpressService' => $vendorDir . '/zoujingli/think-library/src/service/ExpressService.php',

View File

@ -380,7 +380,15 @@ class ComposerStaticInit9eebf462f38fc6a0db482795c8caf813
'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\\queue\\CleanQueue' => __DIR__ . '/..' . '/zoujingli/think-library/src/command/queue/CleanQueue.php',
'think\\admin\\command\\queue\\ListenQueue' => __DIR__ . '/..' . '/zoujingli/think-library/src/command/queue/ListenQueue.php',
'think\\admin\\command\\queue\\QueryQueue' => __DIR__ . '/..' . '/zoujingli/think-library/src/command/queue/QueryQueue.php',
'think\\admin\\command\\queue\\StartQueue' => __DIR__ . '/..' . '/zoujingli/think-library/src/command/queue/StartQueue.php',
'think\\admin\\command\\queue\\StateQueue' => __DIR__ . '/..' . '/zoujingli/think-library/src/command/queue/StateQueue.php',
'think\\admin\\command\\queue\\StopQueue' => __DIR__ . '/..' . '/zoujingli/think-library/src/command/queue/StopQueue.php',
'think\\admin\\command\\queue\\WorkQueue' => __DIR__ . '/..' . '/zoujingli/think-library/src/command/queue/WorkQueue.php',
'think\\admin\\extend\\CodeExtend' => __DIR__ . '/..' . '/zoujingli/think-library/src/extend/CodeExtend.php',
'think\\admin\\extend\\DataExtend' => __DIR__ . '/..' . '/zoujingli/think-library/src/extend/DataExtend.php',
'think\\admin\\extend\\ExcelExtend' => __DIR__ . '/..' . '/zoujingli/think-library/src/extend/ExcelExtend.php',
@ -392,13 +400,6 @@ class ComposerStaticInit9eebf462f38fc6a0db482795c8caf813
'think\\admin\\helper\\SaveHelper' => __DIR__ . '/..' . '/zoujingli/think-library/src/helper/SaveHelper.php',
'think\\admin\\helper\\TokenHelper' => __DIR__ . '/..' . '/zoujingli/think-library/src/helper/TokenHelper.php',
'think\\admin\\helper\\ValidateHelper' => __DIR__ . '/..' . '/zoujingli/think-library/src/helper/ValidateHelper.php',
'think\\admin\\queue\\CleanQueue' => __DIR__ . '/..' . '/zoujingli/think-library/src/queue/CleanQueue.php',
'think\\admin\\queue\\ListenQueue' => __DIR__ . '/..' . '/zoujingli/think-library/src/queue/ListenQueue.php',
'think\\admin\\queue\\QueryQueue' => __DIR__ . '/..' . '/zoujingli/think-library/src/queue/QueryQueue.php',
'think\\admin\\queue\\StartQueue' => __DIR__ . '/..' . '/zoujingli/think-library/src/queue/StartQueue.php',
'think\\admin\\queue\\StateQueue' => __DIR__ . '/..' . '/zoujingli/think-library/src/queue/StateQueue.php',
'think\\admin\\queue\\StopQueue' => __DIR__ . '/..' . '/zoujingli/think-library/src/queue/StopQueue.php',
'think\\admin\\queue\\WorkQueue' => __DIR__ . '/..' . '/zoujingli/think-library/src/queue/WorkQueue.php',
'think\\admin\\service\\AdminService' => __DIR__ . '/..' . '/zoujingli/think-library/src/service/AdminService.php',
'think\\admin\\service\\CaptchaService' => __DIR__ . '/..' . '/zoujingli/think-library/src/service/CaptchaService.php',
'think\\admin\\service\\ExpressService' => __DIR__ . '/..' . '/zoujingli/think-library/src/service/ExpressService.php',

View File

@ -935,12 +935,12 @@
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "608e1bd304e8935c19318540ba328625914e2b44"
"reference": "95cfaa9e2e93adf76a4e28f57157d8f779f55680"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/608e1bd304e8935c19318540ba328625914e2b44",
"reference": "608e1bd304e8935c19318540ba328625914e2b44",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/95cfaa9e2e93adf76a4e28f57157d8f779f55680",
"reference": "95cfaa9e2e93adf76a4e28f57157d8f779f55680",
"shasum": "",
"mirrors": [
{
@ -956,7 +956,7 @@
"ext-json": "*",
"topthink/framework": "^6.0"
},
"time": "2020-01-09T07:53:07+00:00",
"time": "2020-01-10T02:43:12+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-01-09 16:09:21
// This file is automatically generated at:2020-01-10 10:45:43
declare (strict_types = 1);
return array (
0 => 'think\\app\\Service',

View File

@ -79,15 +79,15 @@ class Library extends Service
{
// 注册系统任务指令
$this->commands([
'think\admin\queue\CleanQueue',
'think\admin\queue\WorkQueue',
'think\admin\queue\StopQueue',
'think\admin\queue\StateQueue',
'think\admin\queue\StartQueue',
'think\admin\queue\QueryQueue',
'think\admin\queue\ListenQueue',
'think\admin\command\Install',
'think\admin\command\Version',
'think\admin\command\queue\CleanQueue',
'think\admin\command\queue\WorkQueue',
'think\admin\command\queue\StopQueue',
'think\admin\command\queue\StateQueue',
'think\admin\command\queue\StartQueue',
'think\admin\command\queue\QueryQueue',
'think\admin\command\queue\ListenQueue',
]);
}
}

View File

@ -60,6 +60,18 @@ class Install extends Command
'rules' => ['app/wechat'],
'ignore' => [],
],
'config' => [
'rules' => [
'config/app.php',
'config/cache.php',
'config/log.php',
'config/route.php',
'config/session.php',
'config/trace.php',
'config/view.php',
],
'ignore' => [],
],
'static' => [
'rules' => [
'public/static/plugs',

View File

@ -0,0 +1,51 @@
<?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\service\ProcessService;
use think\console\Command;
use think\console\Input;
use think\console\Output;
/**
* 系统任务基类
* Class Queue
* @package think\admin\command
*/
abstract class Queue extends Command
{
/**
* 绑定数据表
* @var string
*/
protected $table = 'SystemQueue';
/**
* 进程服务对象
* @var ProcessService
*/
protected $process;
/**
* 任务指令初始化
* @param Input $input
* @param Output $output
*/
public function initialize(Input $input, Output $output)
{
$this->process = ProcessService::instance();
}
}

View File

@ -13,20 +13,19 @@
// | github 代码仓库https://github.com/zoujingli/ThinkLibrary
// +----------------------------------------------------------------------
namespace think\admin\queue;
namespace think\admin\command\queue;
use think\admin\service\QueueService;
use think\console\Command;
use think\admin\command\Queue;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
/**
* 清理历史任务记录
* 清理任务历史记录
* Class CleanQueue
* @package think\admin\queue
* @package think\admin\command\queue
*/
class CleanQueue extends Command
class CleanQueue extends Queue
{
/**
* 截止时间
@ -34,12 +33,6 @@ class CleanQueue extends Command
*/
protected $time;
/**
* 绑定数据表
* @var string
*/
protected $table = 'SystemQueue';
/**
* 配置指定信息
*/
@ -65,13 +58,13 @@ class CleanQueue extends Command
$map = [['exec_time', '<', time() - $this->time]];
$count1 = $this->app->db->name($this->table)->where($map)->delete();
$this->output->info("Successfully cleaned up {$count1} history task records");
// 重置超1小时无响应的记录
// 重置超60分钟无响应的记录
$map = [['exec_time', '<', time() - 3600], ['status', '=', '2']];
$count2 = $this->app->db->name($this->table)->where($map)->update(['status' => '4', 'exec_desc' => '执行等待超过1小时无响应']);
$this->output->info("Failed {$count2} records without response after waiting for more than 1 hour");
$count2 = $this->app->db->name($this->table)->where($map)->update(['status' => '4', 'exec_desc' => '执行等待超过60分钟无响应']);
$this->output->info("Successfully processed {$count2} unresponsive records waiting for more than 1 hour");
// 返回消息到任务状态描述
if (defined('WorkQueueCall')) {
throw new \think\Exception("清理{$count1}任务记录,标志{$count2}条超60分钟无响应的任务", 3);
throw new \think\Exception("清理七天前{$count1}记录,标志{$count2}条超60分钟无响应的任务", 3);
}
}
}

View File

@ -13,28 +13,20 @@
// | github 代码仓库https://github.com/zoujingli/ThinkLibrary
// +----------------------------------------------------------------------
namespace think\admin\queue;
namespace think\admin\command\queue;
use think\admin\service\ProcessService;
use think\admin\command\Queue;
use think\Collection;
use think\console\Command;
use think\console\Input;
use think\console\Output;
/**
* 启动监听任务的主进程
* Class ListenQueue
* @package think\admin\queue
* @package think\admin\command\queue
*/
class ListenQueue extends Command
class ListenQueue extends Queue
{
/**
* 当前任务服务
* @var ProcessService
*/
protected $process;
/**
* 配置指定信息
*/
@ -51,14 +43,14 @@ class ListenQueue extends Command
protected function execute(Input $input, Output $output)
{
set_time_limit(0);
$this->app->db->name('SystemQueue')->count();
if (($this->process = ProcessService::instance())->iswin()) {
$this->app->db->name($this->table)->count();
if ($this->process->iswin()) {
$this->setProcessTitle("ThinkAdmin {$this->process->version()} Queue Listen");
}
$output->writeln('============ LISTENING ============');
while (true) {
$where = [['status', '=', '1'], ['exec_time', '<=', time()]];
$this->app->db->name('SystemQueue')->where($where)->order('exec_time asc')->chunk(100, function (Collection $list) {
$this->app->db->name($this->table)->where($where)->order('exec_time asc')->chunk(100, function (Collection $list) {
foreach ($list as $vo) try {
$command = $this->process->think("xtask:_work {$vo['code']} -");
if (count($this->process->query($command)) > 0) {
@ -85,7 +77,7 @@ class ListenQueue extends Command
*/
protected function update($code, array $data = [])
{
return $this->app->db->name('SystemQueue')->where(['code' => $code])->update($data);
return $this->app->db->name($this->table)->where(['code' => $code])->update($data);
}
}

View File

@ -13,19 +13,18 @@
// | github 代码仓库https://github.com/zoujingli/ThinkLibrary
// +----------------------------------------------------------------------
namespace think\admin\queue;
namespace think\admin\command\queue;
use think\admin\service\ProcessService;
use think\console\Command;
use think\admin\command\Queue;
use think\console\Input;
use think\console\Output;
/**
* 查询正在执行的进程PID
* Class QueryQueue
* @package think\admin\queue
* @package think\admin\command\queue
*/
class QueryQueue extends Command
class QueryQueue extends Queue
{
/**
* 指令属性配置
@ -42,8 +41,7 @@ class QueryQueue extends Command
*/
protected function execute(Input $input, Output $output)
{
$service = ProcessService::instance();
$result = $service->query($service->think("xtask:"));
$result = $this->process->query($this->process->think("xtask:"));
if (count($result) > 0) foreach ($result as $item) {
$output->writeln("{$item['pid']}\t{$item['cmd']}");
} else {

View File

@ -13,19 +13,18 @@
// | github 代码仓库https://github.com/zoujingli/ThinkLibrary
// +----------------------------------------------------------------------
namespace think\admin\queue;
namespace think\admin\command\queue;
use think\admin\service\ProcessService;
use think\console\Command;
use think\admin\command\Queue;
use think\console\Input;
use think\console\Output;
/**
* 检查并创建监听主进程
* Class StartQueue
* @package think\admin\queue
* @package think\admin\command\queue
*/
class StartQueue extends Command
class StartQueue extends Queue
{
/**
@ -43,15 +42,14 @@ class StartQueue extends Command
*/
protected function execute(Input $input, Output $output)
{
$this->app->db->name('SystemQueue')->count();
$service = ProcessService::instance();
$command = $service->think("xtask:listen");
if (count($result = $service->query($command)) > 0) {
$this->app->db->name($this->table)->count();
$command = $this->process->think("xtask:listen");
if (count($result = $this->process->query($command)) > 0) {
$output->info("Listening main process {$result['0']['pid']} has started");
} else {
$service->create($command);
$this->process->create($command);
sleep(1);
if (count($result = $service->query($command)) > 0) {
if (count($result = $this->process->query($command)) > 0) {
$output->info("Listening main process {$result['0']['pid']} started successfully");
} else {
$output->error('Failed to create listening main process');

View File

@ -13,19 +13,18 @@
// | github 代码仓库https://github.com/zoujingli/ThinkLibrary
// +----------------------------------------------------------------------
namespace think\admin\queue;
namespace think\admin\command\queue;
use think\admin\service\ProcessService;
use think\console\Command;
use think\admin\command\Queue;
use think\console\Input;
use think\console\Output;
/**
* 查看任务监听主进程状态
* 查看任务监听主进程状态
* Class StateQueue
* @package think\admin\queue
* @package think\admin\command\queue
*/
class StateQueue extends Command
class StateQueue extends Queue
{
/**
* 指令属性配置
@ -42,9 +41,8 @@ class StateQueue extends Command
*/
protected function execute(Input $input, Output $output)
{
$service = ProcessService::instance();
$command = $service->think('xtask:listen');
if (count($result = $service->query($command)) > 0) {
$command = $this->process->think('xtask:listen');
if (count($result = $this->process->query($command)) > 0) {
$output->info("Listening for main process {$result[0]['pid']} running");
} else {
$output->warning("The Listening main process is not running");

View File

@ -13,19 +13,18 @@
// | github 代码仓库https://github.com/zoujingli/ThinkLibrary
// +----------------------------------------------------------------------
namespace think\admin\queue;
namespace think\admin\command\queue;
use think\admin\service\ProcessService;
use think\console\Command;
use think\admin\command\Queue;
use think\console\Input;
use think\console\Output;
/**
* 平滑停止任务的所有进程
* Class StopQueue
* @package think\admin\queue
* @package think\admin\command\queue
*/
class StopQueue extends Command
class StopQueue extends Queue
{
/**
@ -43,11 +42,11 @@ class StopQueue extends Command
*/
protected function execute(Input $input, Output $output)
{
$service = ProcessService::instance();
if (count($result = $service->query($service->think('xtask:'))) < 1) {
$keyword = $this->process->think('xtask:');
if (count($result = $this->process->query($keyword)) < 1) {
$output->warning("There is no task process to finish");
} else foreach ($result as $item) {
$service->close($item['pid']);
$this->process->close($item['pid']);
$output->info("Sending end process {$item['pid']} signal succeeded");
}
}

View File

@ -13,11 +13,10 @@
// | github 代码仓库https://github.com/zoujingli/ThinkLibrary
// +----------------------------------------------------------------------
namespace think\admin\queue;
namespace think\admin\command\queue;
use think\admin\service\ProcessService;
use think\admin\command\Queue;
use think\admin\service\QueueService;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
@ -25,14 +24,14 @@ use think\console\Output;
/**
* 启动独立执行进程
* Class WorkQueue
* @package think\admin\queue
* @package think\admin\command\queue
*/
class WorkQueue extends Command
class WorkQueue extends Queue
{
/**
* 当前任务编号
* @var integer
* @var string
*/
protected $code;
@ -42,12 +41,6 @@ class WorkQueue extends Command
*/
protected $queue;
/**
* 绑定数据表
* @var string
*/
protected $table = 'SystemQueue';
/**
* 配置指定信息
*/
@ -82,8 +75,8 @@ class WorkQueue extends Command
'outer_time' => '0', 'exec_pid' => getmypid(), 'exec_desc' => '', 'status' => '2',
]);
// 设置进程标题
if (($process = ProcessService::instance())->iswin()) {
$this->setProcessTitle("ThinkAdmin {$process->version()} Queue - {$this->queue['title']}");
if ($this->process->iswin()) {
$this->setProcessTitle("ThinkAdmin {$this->process->version()} Queue - {$this->queue['title']}");
}
// 执行任务内容
if (class_exists($command = $this->queue['command'])) {
@ -125,14 +118,12 @@ class WorkQueue extends Command
]);
$this->output->writeln(is_string($message) ? $message : '');
// 注册循环任务
if (isset($this->queue['loops_time']) && $this->queue['loops_time'] > 0) try {
QueueService::instance()->register(
$this->queue['title'], $this->queue['command'], $this->queue['loops_time'],
json_decode($this->queue['exec_data'], true), $this->queue['rscript'], $this->queue['loops_time'],
$this->app->db->name($this->table)->where(['code' => $this->code])->value('attempts') + 1
);
} catch (\Exception $exception) {
$this->app->log->error("Queue {$this->queue['code']} Loops Failed. {$exception->getMessage()}");
if (isset($this->queue['loops_time']) && $this->queue['loops_time'] > 0) {
try {
QueueService::instance()->initialize($this->code)->reset($this->queue['loops_time']);
} catch (\Exception $exception) {
$this->app->log->error("Queue {$this->queue['code']} Loops Failed. {$exception->getMessage()}");
}
}
}

View File

@ -92,16 +92,15 @@ if (!function_exists('sysqueue')) {
* @param array $data 任务附加数据
* @param integer $rscript 任务类型(0单例,1多例)
* @param integer $loops 循环等待时间
* @param integer $attempts 已执行次数
* @return QueueService
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
function sysqueue($title, $command, $later = 0, $data = [], $rscript = 1, $loops = 0, $attempts = 0)
function sysqueue($title, $command, $later = 0, $data = [], $rscript = 1, $loops = 0)
{
return QueueService::instance()->register($title, $command, $later, $data, $rscript, $loops, $attempts);
return QueueService::instance()->register($title, $command, $later, $data, $rscript, $loops);
}
}
if (!function_exists('systoken')) {

View File

@ -26,4 +26,5 @@ return [
'think_library_sort_error' => 'Sorry, modification of list sort failed, please try again later.',
'think_library_page_html' => 'Total %s records, display %s per page, total %s page current display %s page.',
'think_library_csrf_error' => 'Form token validation failed, please refresh and try again later.',
'think_library_queue_exist' => 'Task has been created, please wait for processing to complete.',
];

View File

@ -26,4 +26,5 @@ return [
'think_library_sort_error' => '抱歉,列表排序失败,请稍候再试!',
'think_library_page_html' => '共 %s 条记录,每页显示 %s 条,共 %s 页当前显示第 %s 页。',
'think_library_csrf_error' => '表单令牌验证失败,请刷新页面再试!',
'think_library_queue_exist' => '任务已创建,请等待处理完成!',
];

View File

@ -59,9 +59,10 @@ class QueueService extends Service
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
protected function initialize($code = 0): Service
public function initialize($code = 0): Service
{
if ($code > 0) {
if (!empty($code)) {
$this->code = $code;
$this->queue = $this->app->db->name('SystemQueue')->where(['code' => $this->code])->find();
if (empty($this->queue)) throw new \think\Exception("Queue {$code} Not found.");
$this->code = $this->queue['code'];
@ -118,24 +119,23 @@ class QueueService extends Service
* @param array $data 任务附加数据
* @param integer $rscript 任务类型(0单例,1多例)
* @param integer $loops 循环等待时间
* @param integer $attempts 已执行次数
* @return $this
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function register($title, $command, $later = 0, $data = [], $rscript = 1, $loops = 0, $attempts = 0)
public function register($title, $command, $later = 0, $data = [], $rscript = 1, $loops = 0)
{
$map = [['title', '=', $title], ['status', 'in', ['1', '2']]];
if (empty($rscript) && $this->app->db->name('SystemQueue')->where($map)->count() > 0) {
throw new \think\Exception('该任务已经创建,请耐心等待处理完成!');
throw new \think\Exception(lang('think_library_queue_exist'));
}
$this->app->db->name('SystemQueue')->strict(false)->failException(true)->insert([
'code' => $this->code = CodeExtend::uniqidDate(16),
'code' => $this->code = 'QE' . CodeExtend::uniqidDate(16),
'title' => $title,
'command' => $command,
'attempts' => $attempts,
'attempts' => '0',
'rscript' => intval(boolval($rscript)),
'exec_data' => json_encode($data, JSON_UNESCAPED_UNICODE),
'exec_time' => $later > 0 ? time() + $later : time(),