ComposerUpdate

This commit is contained in:
Anyon 2019-12-02 10:51:37 +08:00
parent 77fc2b0fa2
commit 9a14e8dbe5
22 changed files with 174 additions and 76 deletions

20
composer.lock generated
View File

@ -151,16 +151,16 @@
}, },
{ {
"name": "opis/closure", "name": "opis/closure",
"version": "3.4.1", "version": "3.5.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/opis/closure.git", "url": "https://github.com/opis/closure.git",
"reference": "e79f851749c3caa836d7ccc01ede5828feb762c7" "reference": "93ebc5712cdad8d5f489b500c59d122df2e53969"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/opis/closure/zipball/e79f851749c3caa836d7ccc01ede5828feb762c7", "url": "https://api.github.com/repos/opis/closure/zipball/93ebc5712cdad8d5f489b500c59d122df2e53969",
"reference": "e79f851749c3caa836d7ccc01ede5828feb762c7", "reference": "93ebc5712cdad8d5f489b500c59d122df2e53969",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -179,7 +179,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "3.3.x-dev" "dev-master": "3.5.x-dev"
} }
}, },
"autoload": { "autoload": {
@ -214,7 +214,7 @@
"serialization", "serialization",
"serialize" "serialize"
], ],
"time": "2019-10-19T18:38:51+00:00" "time": "2019-11-29T22:36:02+00:00"
}, },
{ {
"name": "psr/cache", "name": "psr/cache",
@ -783,12 +783,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git", "url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "ba4fe10a27cff9fb5bbd2a4673e0c65fb3040e62" "reference": "82a60f7d4b2362e27318e696a231a124e5c2c793"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/ba4fe10a27cff9fb5bbd2a4673e0c65fb3040e62", "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/82a60f7d4b2362e27318e696a231a124e5c2c793",
"reference": "ba4fe10a27cff9fb5bbd2a4673e0c65fb3040e62", "reference": "82a60f7d4b2362e27318e696a231a124e5c2c793",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -832,7 +832,7 @@
], ],
"description": "ThinkPHP v6.0 Development Library", "description": "ThinkPHP v6.0 Development Library",
"homepage": "http://framework.thinkadmin.top", "homepage": "http://framework.thinkadmin.top",
"time": "2019-11-29T01:31:35+00:00" "time": "2019-12-02T02:46:31+00:00"
} }
], ],
"packages-dev": [], "packages-dev": [],

View File

@ -148,17 +148,17 @@
}, },
{ {
"name": "opis/closure", "name": "opis/closure",
"version": "3.4.1", "version": "3.5.1",
"version_normalized": "3.4.1.0", "version_normalized": "3.5.1.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/opis/closure.git", "url": "https://github.com/opis/closure.git",
"reference": "e79f851749c3caa836d7ccc01ede5828feb762c7" "reference": "93ebc5712cdad8d5f489b500c59d122df2e53969"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/opis/closure/zipball/e79f851749c3caa836d7ccc01ede5828feb762c7", "url": "https://api.github.com/repos/opis/closure/zipball/93ebc5712cdad8d5f489b500c59d122df2e53969",
"reference": "e79f851749c3caa836d7ccc01ede5828feb762c7", "reference": "93ebc5712cdad8d5f489b500c59d122df2e53969",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -174,11 +174,11 @@
"jeremeamia/superclosure": "^2.0", "jeremeamia/superclosure": "^2.0",
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
}, },
"time": "2019-10-19T18:38:51+00:00", "time": "2019-11-29T22:36:02+00:00",
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "3.3.x-dev" "dev-master": "3.5.x-dev"
} }
}, },
"installation-source": "dist", "installation-source": "dist",
@ -805,12 +805,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git", "url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "ba4fe10a27cff9fb5bbd2a4673e0c65fb3040e62" "reference": "82a60f7d4b2362e27318e696a231a124e5c2c793"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/ba4fe10a27cff9fb5bbd2a4673e0c65fb3040e62", "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/82a60f7d4b2362e27318e696a231a124e5c2c793",
"reference": "ba4fe10a27cff9fb5bbd2a4673e0c65fb3040e62", "reference": "82a60f7d4b2362e27318e696a231a124e5c2c793",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -826,7 +826,7 @@
"ext-json": "*", "ext-json": "*",
"topthink/framework": "^6.0" "topthink/framework": "^6.0"
}, },
"time": "2019-11-29T01:31:35+00:00", "time": "2019-12-02T02:46:31+00:00",
"type": "library", "type": "library",
"extra": { "extra": {
"think": { "think": {

View File

@ -1,6 +1,19 @@
CHANGELOG CHANGELOG
--------- ---------
### v3.5.1, 2019.11.30
- Bugfix. See #47
### v3.5.0, 2019.11.29
- Added support for short closures (arrow functions)
- Added `isShortClosure` method to `Opis\Closure\ReflectionClosure`
### v3.4.2, 2019.11.29
- Added `stream_set_option()`
### v3.4.1, 2019.10.19 ### v3.4.1, 2019.10.19
- Fixed a [bug](https://github.com/opis/closure/issues/40) that prevented serialization to work correctly. - Fixed a [bug](https://github.com/opis/closure/issues/40) that prevented serialization to work correctly.

View File

@ -61,7 +61,7 @@ Or you could directly reference it into your `composer.json` file as a dependenc
```json ```json
{ {
"require": { "require": {
"opis/closure": "^3.4" "opis/closure": "^3.5"
} }
} }
``` ```

View File

@ -34,7 +34,7 @@
}, },
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "3.3.x-dev" "dev-master": "3.5.x-dev"
} }
} }
} }

View File

@ -41,6 +41,11 @@ class ClosureStream
return $this->pointer >= $this->length; return $this->pointer >= $this->length;
} }
public function stream_set_option($option, $arg1, $arg2)
{
return false;
}
public function stream_stat() public function stream_stat()
{ {
$stat = stat(__FILE__); $stat = stat(__FILE__);

View File

@ -19,6 +19,7 @@ class ReflectionClosure extends ReflectionFunction
protected $isStaticClosure; protected $isStaticClosure;
protected $isScopeRequired; protected $isScopeRequired;
protected $isBindingRequired; protected $isBindingRequired;
protected $isShortClosure;
protected static $files = array(); protected static $files = array();
protected static $classes = array(); protected static $classes = array();
@ -51,6 +52,19 @@ class ReflectionClosure extends ReflectionFunction
return $this->isStaticClosure; return $this->isStaticClosure;
} }
public function isShortClosure()
{
if ($this->isShortClosure === null) {
$code = $this->getCode();
if ($this->isStatic()) {
$code = substr($code, 6);
}
$this->isShortClosure = strtolower(substr(trim($code), 0, 2)) === 'fn';
}
return $this->isShortClosure;
}
/** /**
* @return string * @return string
*/ */
@ -70,6 +84,7 @@ class ReflectionClosure extends ReflectionFunction
} }
$className = null; $className = null;
$fn = false;
if (null !== $className = $this->getClosureScopeClass()) { if (null !== $className = $this->getClosureScopeClass()) {
@ -89,6 +104,7 @@ class ReflectionClosure extends ReflectionFunction
default: default:
$php7_types = array('string', 'int', 'bool', 'float', 'void', 'object'); $php7_types = array('string', 'int', 'bool', 'float', 'void', 'object');
} }
$fn = PHP_MINOR_VERSION === 4;
} }
$ns = $this->getNamespaceName(); $ns = $this->getNamespaceName();
@ -107,6 +123,7 @@ class ReflectionClosure extends ReflectionFunction
$tokens = $this->getTokens(); $tokens = $this->getTokens();
$state = $lastState = 'start'; $state = $lastState = 'start';
$inside_anonymous = false; $inside_anonymous = false;
$isShortClosure = false;
$anonymous_mark = 0; $anonymous_mark = 0;
$open = 0; $open = 0;
$code = ''; $code = '';
@ -124,6 +141,10 @@ class ReflectionClosure extends ReflectionFunction
if ($token[0] === T_FUNCTION || $token[0] === T_STATIC) { if ($token[0] === T_FUNCTION || $token[0] === T_STATIC) {
$code .= $token[1]; $code .= $token[1];
$state = $token[0] === T_FUNCTION ? 'function' : 'static'; $state = $token[0] === T_FUNCTION ? 'function' : 'static';
} elseif ($fn && $token[0] === T_FN) {
$isShortClosure = true;
$code .= $token[1];
$state = 'closure_args';
} }
break; break;
case 'static': case 'static':
@ -132,6 +153,10 @@ class ReflectionClosure extends ReflectionFunction
if ($token[0] === T_FUNCTION) { if ($token[0] === T_FUNCTION) {
$state = 'function'; $state = 'function';
} }
} elseif ($fn && $token[0] === T_FN) {
$isShortClosure = true;
$code .= $token[1];
$state = 'closure_args';
} else { } else {
$code = ''; $code = '';
$state = 'start'; $state = 'start';
@ -155,6 +180,10 @@ class ReflectionClosure extends ReflectionFunction
if($token[0] === T_FUNCTION || $token[0] === T_STATIC){ if($token[0] === T_FUNCTION || $token[0] === T_STATIC){
$code = $token[1]; $code = $token[1];
$state = $token[0] === T_FUNCTION ? 'function' : 'static'; $state = $token[0] === T_FUNCTION ? 'function' : 'static';
} elseif ($fn && $token[0] === T_FN) {
$isShortClosure = true;
$code .= $token[1];
$state = 'closure_args';
} }
break; break;
case 'closure_args': case 'closure_args':
@ -172,6 +201,12 @@ class ReflectionClosure extends ReflectionFunction
$code .= $token[1]; $code .= $token[1];
$state = 'use'; $state = 'use';
break; break;
case T_DOUBLE_ARROW:
$code .= $token[1];
if ($isShortClosure) {
$state = 'closure';
}
break;
case '=': case '=':
$code .= $token; $code .= $token;
$lastState = 'closure_args'; $lastState = 'closure_args';
@ -226,6 +261,12 @@ class ReflectionClosure extends ReflectionFunction
$state = 'id_name'; $state = 'id_name';
$lastState = 'return'; $lastState = 'return';
break 2; break 2;
case T_DOUBLE_ARROW:
$code .= $token[1];
if ($isShortClosure) {
$state = 'closure';
}
break;
case '{': case '{':
$code .= '{'; $code .= '{';
$state = 'closure'; $state = 'closure';
@ -247,12 +288,36 @@ class ReflectionClosure extends ReflectionFunction
break; break;
case '}': case '}':
$code .= '}'; $code .= '}';
if(--$open === 0){ if(--$open === 0 && !$isShortClosure){
break 3; break 3;
} elseif ($inside_anonymous) { } elseif ($inside_anonymous) {
$inside_anonymous = !($open === $anonymous_mark); $inside_anonymous = !($open === $anonymous_mark);
} }
break; break;
case '(':
case '[':
$code .= $token[0];
if ($isShortClosure) {
$open++;
}
break;
case ')':
case ']':
if ($isShortClosure) {
if ($open === 0) {
break 3;
}
--$open;
}
$code .= $token[0];
break;
case ',':
case ';':
if ($isShortClosure && $open === 0) {
break 3;
}
$code .= $token[0];
break;
case T_LINE: case T_LINE:
$code .= $token[2] - $line + $lineAdd; $code .= $token[2] - $line + $lineAdd;
break; break;
@ -432,6 +497,9 @@ class ReflectionClosure extends ReflectionFunction
$id_name .= $token[1]; $id_name .= $token[1];
break; break;
case '(': case '(':
if ($isShortClosure) {
$open++;
}
if($context === 'new' || false !== strpos($id_name, '\\')){ if($context === 'new' || false !== strpos($id_name, '\\')){
if($id_start !== '\\'){ if($id_start !== '\\'){
if ($classes === null) { if ($classes === null) {
@ -538,10 +606,17 @@ class ReflectionClosure extends ReflectionFunction
} }
} }
if ($isShortClosure) {
$code .= ';';
$this->useVariables = $this->getStaticVariables();
} else {
$this->useVariables = empty($use) ? $use : array_intersect_key($this->getStaticVariables(), array_flip($use));
}
$this->isShortClosure = $isShortClosure;
$this->isBindingRequired = $isUsingThisObject; $this->isBindingRequired = $isUsingThisObject;
$this->isScopeRequired = $isUsingScope; $this->isScopeRequired = $isUsingScope;
$this->code = $code; $this->code = $code;
$this->useVariables = empty($use) ? $use : array_intersect_key($this->getStaticVariables(), array_flip($use));
return $this->code; return $this->code;
} }

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php <?php
// This file is automatically generated at:2019-11-29 11:11:35 // This file is automatically generated at:2019-12-02 10:51:21
declare (strict_types = 1); declare (strict_types = 1);
return array ( return array (
0 => 'think\\app\\Service', 0 => 'think\\app\\Service',

View File

@ -26,18 +26,18 @@ class DataExtend
/** /**
* 一维数据数组生成数据树 * 一维数据数组生成数据树
* @param array $list 数据列表 * @param array $list 数据列表
* @param string $id 父ID Key * @param string $key ID_KEY
* @param string $pid ID Key * @param string $pkey PID_KEY
* @param string $son 定义子数据Key * @param string $skey 子数据名称
* @return array * @return array
*/ */
public static function arr2tree($list, $id = 'id', $pid = 'pid', $son = 'sub') public static function arr2tree($list, $key = 'id', $pkey = 'pid', $skey = 'sub')
{ {
list($tree, $map) = [[], []]; list($tree, $map) = [[], []];
foreach ($list as $item) $map[$item[$id]] = $item; foreach ($list as $item) $map[$item[$key]] = $item;
foreach ($list as $item) if (isset($item[$pid]) && isset($map[$item[$pid]])) { foreach ($list as $item) if (isset($item[$pkey]) && isset($map[$item[$pkey]])) {
$map[$item[$pid]][$son][] = &$map[$item[$id]]; $map[$item[$pkey]][$skey][] = &$map[$item[$key]];
} else $tree[] = &$map[$item[$id]]; } else $tree[] = &$map[$item[$key]];
unset($map); unset($map);
return $tree; return $tree;
} }
@ -45,24 +45,24 @@ class DataExtend
/** /**
* 一维数据数组生成数据树 * 一维数据数组生成数据树
* @param array $list 数据列表 * @param array $list 数据列表
* @param string $id ID Key * @param string $key ID_KEY
* @param string $pid 父ID Key * @param string $pkey PID_KEY
* @param string $path * @param string $path
* @param string $ppath * @param string $ppath
* @return array * @return array
*/ */
public static function arr2table(array $list, $id = 'id', $pid = 'pid', $path = 'path', $ppath = '') public static function arr2table(array $list, $key = 'id', $pkey = 'pid', $path = 'path', $ppath = '')
{ {
$tree = []; $tree = [];
foreach (self::arr2tree($list, $id, $pid) as $attr) { foreach (self::arr2tree($list, $key, $pkey) as $attr) {
$attr[$path] = "{$ppath}-{$attr[$id]}"; $attr[$path] = "{$ppath}-{$attr[$key]}";
$attr['sub'] = isset($attr['sub']) ? $attr['sub'] : []; $attr['sub'] = isset($attr['sub']) ? $attr['sub'] : [];
$attr['spt'] = substr_count($ppath, '-'); $attr['spt'] = substr_count($ppath, '-');
$attr['spl'] = str_repeat(" ├ ", $attr['spt']); $attr['spl'] = str_repeat(" ├ ", $attr['spt']);
$sub = $attr['sub']; $sub = $attr['sub'];
unset($attr['sub']); unset($attr['sub']);
$tree[] = $attr; $tree[] = $attr;
if (!empty($sub)) $tree = array_merge($tree, self::arr2table($sub, $id, $pid, $path, $attr[$path])); if (!empty($sub)) $tree = array_merge($tree, self::arr2table($sub, $key, $pkey, $path, $attr[$path]));
} }
return $tree; return $tree;
} }
@ -70,9 +70,9 @@ class DataExtend
/** /**
* 获取数据树子ID * 获取数据树子ID
* @param array $list 数据列表 * @param array $list 数据列表
* @param int $id 起始ID * @param integer $id 起始ID
* @param string $key 子Key * @param string $key ID_KEY
* @param string $pkey 父Key * @param string $pkey PID_KEY
* @return array * @return array
*/ */
public static function getArrSubIds($list, $id = 0, $key = 'id', $pkey = 'pid') public static function getArrSubIds($list, $id = 0, $key = 'id', $pkey = 'pid')

View File

@ -62,7 +62,7 @@ class FormHelper extends Helper
* @param string $field 指定数据主键 * @param string $field 指定数据主键
* @param array $where 额外更新条件 * @param array $where 额外更新条件
* @param array $data 表单扩展数据 * @param array $data 表单扩展数据
* @return array|boolean * @return array|boolean|mixed
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException

View File

@ -56,7 +56,7 @@ class PageHelper extends Helper
* @param boolean $display 是否渲染模板 * @param boolean $display 是否渲染模板
* @param boolean $total 集合分页记录数 * @param boolean $total 集合分页记录数
* @param integer $limit 集合每页记录数 * @param integer $limit 集合每页记录数
* @return array * @return array|mixed
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException

View File

@ -37,14 +37,15 @@ class ListenQueue extends Command
/** /**
* 执行进程守护监听 * 执行进程守护监听
* @param Input $input * @param Input $input 输入对象
* @param Output $output * @param Output $output 输出对象
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
protected function execute(Input $input, Output $output) protected function execute(Input $input, Output $output)
{ {
set_time_limit(0);
$this->app->db->name('SystemQueue')->count(); $this->app->db->name('SystemQueue')->count();
if (($process = ProcessService::instance())->iswin()) { if (($process = ProcessService::instance())->iswin()) {
$this->setProcessTitle("ThinkAdmin 监听主进程 {$process->version()}"); $this->setProcessTitle("ThinkAdmin 监听主进程 {$process->version()}");
@ -52,18 +53,18 @@ class ListenQueue extends Command
$output->writeln('============ 任务监听中 ============'); $output->writeln('============ 任务监听中 ============');
while (true) { while (true) {
$where = [['status', '=', '1'], ['exec_time', '<=', time()]]; $where = [['status', '=', '1'], ['exec_time', '<=', time()]];
$this->app->db->name('SystemQueue')->where($where)->order('exec_time asc')->limit(100)->select()->each(function ($vo) use ($process, $output) { $this->app->db->name('SystemQueue')->where($where)->order('exec_time asc')->limit(100)->select()->each(function ($vo) use ($process) {
try { try {
$this->update($vo['code'], ['status' => '2', 'enter_time' => time(), 'exec_desc' => '', 'attempts' => $vo['attempts'] + 1]); $command = $process->think("xtask:_work {$vo['code']} -");
if ($process->query($command = $process->think("xtask:_work {$vo['code']} -"))) { if (count($process->query($command)) > 0) {
$output->writeln("正在执行 -> [{$vo['code']}] {$vo['title']}"); $this->output->warning("正在执行 -> [{$vo['code']}] {$vo['title']}");
} else { } else {
$process->create($command); $process->create($command);
$output->writeln("创建成功 -> [{$vo['code']}] {$vo['title']}"); $this->output->info("开始执行 -> [{$vo['code']}] {$vo['title']}");
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$this->update($vo['code'], ['status' => '4', 'outer_time' => time(), 'exec_desc' => $e->getMessage()]); $this->update($vo['code'], ['status' => '4', 'outer_time' => time(), 'exec_desc' => $e->getMessage()]);
$output->writeln("创建失败 -> [{$vo['code']}] {$vo['title']}{$e->getMessage()}"); $this->output->error("执行失败 -> [{$vo['code']}] {$vo['title']}{$e->getMessage()}");
} }
}); });
sleep(1); sleep(1);

View File

@ -37,8 +37,8 @@ class QueryQueue extends Command
/** /**
* 执行相关进程查询 * 执行相关进程查询
* @param Input $input * @param Input $input 输入对象
* @param Output $output * @param Output $output 输出对象
*/ */
protected function execute(Input $input, Output $output) protected function execute(Input $input, Output $output)
{ {

View File

@ -38,8 +38,8 @@ class StartQueue extends Command
/** /**
* 执行启动操作 * 执行启动操作
* @param Input $input * @param Input $input 输入对象
* @param Output $output * @param Output $output 输出对象
*/ */
protected function execute(Input $input, Output $output) protected function execute(Input $input, Output $output)
{ {
@ -47,14 +47,14 @@ class StartQueue extends Command
$process = ProcessService::instance(); $process = ProcessService::instance();
$command = $process->think("xtask:listen"); $command = $process->think("xtask:listen");
if (count($result = $process->query($command)) > 0) { if (count($result = $process->query($command)) > 0) {
$output->writeln("监听主进程{$result['0']['pid']}已经启动!"); $output->info("监听主进程{$result['0']['pid']}已经启动!");
} else { } else {
$process->create($command); $process->create($command);
sleep(1); sleep(1);
if (count($result = $process->query($command)) > 0) { if (count($result = $process->query($command)) > 0) {
$output->writeln("监听主进程{$result['0']['pid']}启动成功!"); $output->info("监听主进程{$result['0']['pid']}启动成功!");
} else { } else {
$output->writeln('监听主进程创建失败!'); $output->error('监听主进程创建失败!');
} }
} }
} }

View File

@ -45,9 +45,9 @@ class StateQueue extends Command
$process = ProcessService::instance(); $process = ProcessService::instance();
$command = $process->think('xtask:listen'); $command = $process->think('xtask:listen');
if (count($result = $process->query($command)) > 0) { if (count($result = $process->query($command)) > 0) {
$output->writeln("任务监听主进程{$result[0]['pid']}正在运行..."); $output->info("任务监听主进程{$result[0]['pid']}正在运行...");
} else { } else {
$output->writeln("任务监听主进程没有运行哦!"); $output->warning("任务监听主进程没有运行哦!");
} }
} }
} }

View File

@ -46,10 +46,10 @@ class StopQueue extends Command
$process = ProcessService::instance(); $process = ProcessService::instance();
$command = $process->think('xtask:'); $command = $process->think('xtask:');
if (count($result = $process->query($command)) < 1) { if (count($result = $process->query($command)) < 1) {
$output->writeln("没有需要结束的任务进程哦!"); $output->warning("没有需要结束的任务进程哦!");
} else foreach ($result as $item) { } else foreach ($result as $item) {
$process->close($item['pid']); $process->close($item['pid']);
$output->writeln("发送结束进程{$item['pid']}信号成功!"); $output->info("发送结束进程{$item['pid']}信号成功!");
} }
} }
} }

View File

@ -50,22 +50,26 @@ class WorkQueue extends Command
{ {
$this->setName('xtask:_work')->setDescription('[执行]创建执行任务的进程'); $this->setName('xtask:_work')->setDescription('[执行]创建执行任务的进程');
$this->addArgument('code', Argument::OPTIONAL, '任务编号'); $this->addArgument('code', Argument::OPTIONAL, '任务编号');
$this->addArgument('splt', Argument::OPTIONAL, '指令结束符'); $this->addArgument('spts', Argument::OPTIONAL, '指令结束符');
} }
/** /**
* 任务执行 * @param Input $input 输入对象
* @param Input $input * @param Output $output 输出对象
* @param Output $output
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
*/ */
protected function execute(Input $input, Output $output) protected function execute(Input $input, Output $output)
{ {
try { try {
set_time_limit(0);
$this->code = trim($input->getArgument('code')); $this->code = trim($input->getArgument('code'));
if (empty($this->code)) throw new Exception("执行任务需要指定任务编号!"); if (empty($this->code)) throw new Exception("执行任务需要指定任务编号!");
$queue = $this->app->db->name('SystemQueue')->where(['code' => $this->code, 'status' => '2'])->find(); $queue = $this->app->db->name('SystemQueue')->where(['code' => $this->code, 'status' => '1'])->find();
if (empty($queue)) throw new Exception("执行任务{$this->code}的信息或状态异常!");; 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()) { if (($process = ProcessService::instance())->iswin()) {
$this->setProcessTitle("ThinkAdmin {$process->version()} 执行任务 - {$queue['title']}"); $this->setProcessTitle("ThinkAdmin {$process->version()} 执行任务 - {$queue['title']}");

View File

@ -85,7 +85,7 @@ class AdminService extends Service
/** /**
* 初始化用户权限 * 初始化用户权限
* @param boolean $force 强刷权限 * @param boolean $force 强刷权限
* @return AdminService * @return $this
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException

View File

@ -56,8 +56,8 @@ class InstallService extends Service
protected $ignore = []; protected $ignore = [];
/** /**
* 服务初始化 * 初始化服务
* @return static * @return $this
*/ */
public function initialize(): Service public function initialize(): Service
{ {

View File

@ -48,7 +48,7 @@ class ProcessService extends Service
/** /**
* 创建异步进程 * 创建异步进程
* @param string $command 任务指令 * @param string $command 任务指令
* @return ProcessService * @return $this
*/ */
public function create($command) public function create($command)
{ {

View File

@ -85,7 +85,7 @@ class SystemService extends Service
* @param array $data 需要保存或更新的数据 * @param array $data 需要保存或更新的数据
* @param string $key 条件主键限制 * @param string $key 条件主键限制
* @param array $where 其它的where条件 * @param array $where 其它的where条件
* @return bool|int|mixed|string * @return boolean|integer
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException

View File

@ -53,7 +53,7 @@ class TokenService extends Service
/** /**
* 清理表单CSRF信息 * 清理表单CSRF信息
* @param string $token * @param string $token
* @return TokenService * @return $this
*/ */
public function clearFormToken($token = null) public function clearFormToken($token = null)
{ {