mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
调整后台日志配置
This commit is contained in:
parent
b4dce73afa
commit
8169dcd92b
@ -63,6 +63,30 @@ class Oplog extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志行为配置
|
||||||
|
* @auth true
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public function config()
|
||||||
|
{
|
||||||
|
if ($this->request->isGet()) {
|
||||||
|
$this->fetch();
|
||||||
|
} else {
|
||||||
|
$data = $this->_vali([
|
||||||
|
'oplog_state.in:0,1' => '日志状态值异常!',
|
||||||
|
'oplog_state.require' => '日志状态不能为空!',
|
||||||
|
'oplog_days.require' => '保存天数不能为空!',
|
||||||
|
]);
|
||||||
|
foreach ($data as $name => $value) {
|
||||||
|
sysconf($name, $value);
|
||||||
|
}
|
||||||
|
$this->success('日志配置成功!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清理系统日志
|
* 清理系统日志
|
||||||
* @auth true
|
* @auth true
|
||||||
|
@ -78,27 +78,6 @@ class Plugs extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据变更日志
|
|
||||||
* @login true
|
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
|
||||||
* @throws \think\db\exception\DbException
|
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
|
||||||
*/
|
|
||||||
public function oplog()
|
|
||||||
{
|
|
||||||
if (AdminService::instance()->isSuper()) {
|
|
||||||
$data = $this->_vali([
|
|
||||||
'state.in:0,1' => '状态值范围错误!',
|
|
||||||
'state.require' => '状态值不能为空!',
|
|
||||||
]);
|
|
||||||
sysconf('base.oplog_state', $data['state']);
|
|
||||||
$this->success('数据变更日志切换成功!');
|
|
||||||
} else {
|
|
||||||
$this->error('只有超级管理员才能操作!');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前运行模式
|
* 当前运行模式
|
||||||
* @login true
|
* @login true
|
||||||
|
@ -21,7 +21,7 @@ try {
|
|||||||
/*! 全局数据变更数据 */
|
/*! 全局数据变更数据 */
|
||||||
$GLOBALS['oplogs'] = [];
|
$GLOBALS['oplogs'] = [];
|
||||||
/*! 数据变更日志开关状态 */
|
/*! 数据变更日志开关状态 */
|
||||||
if (sysconf('base.oplog_state')) {
|
if (sysconf('base.oplog_state') && ($days = floatval(sysoplog('base.oplog_days'))) > 0) {
|
||||||
/*! 数据变更批量写入 */
|
/*! 数据变更批量写入 */
|
||||||
app()->event->listen('HttpEnd', function () {
|
app()->event->listen('HttpEnd', function () {
|
||||||
if (is_array($GLOBALS['oplogs']) && count($GLOBALS['oplogs']) > 0) {
|
if (is_array($GLOBALS['oplogs']) && count($GLOBALS['oplogs']) > 0) {
|
||||||
@ -30,7 +30,7 @@ try {
|
|||||||
}
|
}
|
||||||
$GLOBALS['oplogs'] = [];
|
$GLOBALS['oplogs'] = [];
|
||||||
if (rand(1, 100) <= 10) { /*! 清理一周前的日志记录 */
|
if (rand(1, 100) <= 10) { /*! 清理一周前的日志记录 */
|
||||||
$lastdate = date('Y-m-d H:i:s', strtotime('-7days'));
|
$lastdate = date('Y-m-d H:i:s', strtotime("-{$days}days"));
|
||||||
app()->db->name('SystemOplog')->where('create_at', '<', $lastdate)->delete();
|
app()->db->name('SystemOplog')->where('create_at', '<', $lastdate)->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
29
app/admin/view/oplog/config.html
Normal file
29
app/admin/view/oplog/config.html
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<form onsubmit="return false" data-auto="true" action="{:request()->url()}" method="post" class='layui-form layui-card' autocomplete="off">
|
||||||
|
<div class="layui-card-body padding-left-40">
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<span class="color-green font-w7 label-required-prev">记录数据变更日志</span>
|
||||||
|
<div>
|
||||||
|
{foreach [1 => '记录数据变更日志',0 => '不记录数据变更日志'] as $k=>$v}
|
||||||
|
{if intval(sysconf('base.oplog_state')) eq $k}
|
||||||
|
<label class="think-radio">
|
||||||
|
<input checked type="radio" value="{$k}" name="oplog_state">{$v}
|
||||||
|
</label>
|
||||||
|
{else}
|
||||||
|
<label class="think-radio">
|
||||||
|
<input type="radio" value="{$k}" name="oplog_state">{$v}
|
||||||
|
</label>
|
||||||
|
{/if}{/foreach}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<label class="layui-form-item relative block">
|
||||||
|
<span class="color-green font-w7">操作日志保留天数</span>
|
||||||
|
<input class="layui-input" required data-blur-number="0" name="oplog_days" value="{:sysconf('base.oplog_days')?:0}">
|
||||||
|
<p class="help-block">注意:当日志保留天数设置为 0 时则为永久保留日志,系统不会进行删除!</p>
|
||||||
|
</label>
|
||||||
|
<div class="hr-line-dashed "></div>
|
||||||
|
<div class="layui-form-item text-center">
|
||||||
|
<button class="layui-btn" type="submit">保存配置</button>
|
||||||
|
<button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消修改吗?" data-close>取消修改</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
@ -1,19 +1,8 @@
|
|||||||
{extend name='main'}
|
{extend name='main'}
|
||||||
|
|
||||||
{block name="button"}
|
{block name="button"}
|
||||||
<!--{if isset($isSupper) and $isSupper}-->
|
<!--{if auth('config')}-->
|
||||||
<div class="layui-form inline-block">
|
<a class="layui-btn layui-btn-sm layui-btn-primary" data-modal="{:url('config')}">日志配置</a>
|
||||||
<!--{if intval(sysconf('base.oplog_state')) eq 1}-->
|
|
||||||
<input type="checkbox" title="数据变更日志" value="0" checked lay-filter="OplogState">
|
|
||||||
<!--{else}-->
|
|
||||||
<input type="checkbox" title="数据变更日志" value="1" lay-filter="OplogState">
|
|
||||||
<!--{/if}-->
|
|
||||||
<script>
|
|
||||||
form.render(), form.on('checkbox(OplogState)', function (elem) {
|
|
||||||
$.form.load('{:url("admin/api.plugs/oplog")}', {state: elem.value});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</div>
|
|
||||||
<!--{/if}-->
|
<!--{/if}-->
|
||||||
|
|
||||||
<!--{if auth("clear")}-->
|
<!--{if auth("clear")}-->
|
||||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -4,4 +4,4 @@
|
|||||||
|
|
||||||
require_once __DIR__ . '/composer/autoload_real.php';
|
require_once __DIR__ . '/composer/autoload_real.php';
|
||||||
|
|
||||||
return ComposerAutoloaderInit7ad2dfd941224dedfd9e69a3187017d8::getLoader();
|
return ComposerAutoloaderInitc847eb2c7a922ed862fa0bfb18edd00b::getLoader();
|
||||||
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
// autoload_real.php @generated by Composer
|
// autoload_real.php @generated by Composer
|
||||||
|
|
||||||
class ComposerAutoloaderInit7ad2dfd941224dedfd9e69a3187017d8
|
class ComposerAutoloaderInitc847eb2c7a922ed862fa0bfb18edd00b
|
||||||
{
|
{
|
||||||
private static $loader;
|
private static $loader;
|
||||||
|
|
||||||
@ -22,15 +22,15 @@ class ComposerAutoloaderInit7ad2dfd941224dedfd9e69a3187017d8
|
|||||||
return self::$loader;
|
return self::$loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
spl_autoload_register(array('ComposerAutoloaderInit7ad2dfd941224dedfd9e69a3187017d8', 'loadClassLoader'), true, true);
|
spl_autoload_register(array('ComposerAutoloaderInitc847eb2c7a922ed862fa0bfb18edd00b', 'loadClassLoader'), true, true);
|
||||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
||||||
spl_autoload_unregister(array('ComposerAutoloaderInit7ad2dfd941224dedfd9e69a3187017d8', 'loadClassLoader'));
|
spl_autoload_unregister(array('ComposerAutoloaderInitc847eb2c7a922ed862fa0bfb18edd00b', 'loadClassLoader'));
|
||||||
|
|
||||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||||
if ($useStaticLoader) {
|
if ($useStaticLoader) {
|
||||||
require_once __DIR__ . '/autoload_static.php';
|
require_once __DIR__ . '/autoload_static.php';
|
||||||
|
|
||||||
call_user_func(\Composer\Autoload\ComposerStaticInit7ad2dfd941224dedfd9e69a3187017d8::getInitializer($loader));
|
call_user_func(\Composer\Autoload\ComposerStaticInitc847eb2c7a922ed862fa0bfb18edd00b::getInitializer($loader));
|
||||||
} else {
|
} else {
|
||||||
$map = require __DIR__ . '/autoload_namespaces.php';
|
$map = require __DIR__ . '/autoload_namespaces.php';
|
||||||
foreach ($map as $namespace => $path) {
|
foreach ($map as $namespace => $path) {
|
||||||
@ -51,19 +51,19 @@ class ComposerAutoloaderInit7ad2dfd941224dedfd9e69a3187017d8
|
|||||||
$loader->register(true);
|
$loader->register(true);
|
||||||
|
|
||||||
if ($useStaticLoader) {
|
if ($useStaticLoader) {
|
||||||
$includeFiles = Composer\Autoload\ComposerStaticInit7ad2dfd941224dedfd9e69a3187017d8::$files;
|
$includeFiles = Composer\Autoload\ComposerStaticInitc847eb2c7a922ed862fa0bfb18edd00b::$files;
|
||||||
} else {
|
} else {
|
||||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||||
}
|
}
|
||||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||||
composerRequire7ad2dfd941224dedfd9e69a3187017d8($fileIdentifier, $file);
|
composerRequirec847eb2c7a922ed862fa0bfb18edd00b($fileIdentifier, $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $loader;
|
return $loader;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function composerRequire7ad2dfd941224dedfd9e69a3187017d8($fileIdentifier, $file)
|
function composerRequirec847eb2c7a922ed862fa0bfb18edd00b($fileIdentifier, $file)
|
||||||
{
|
{
|
||||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||||
require $file;
|
require $file;
|
||||||
|
10
vendor/composer/autoload_static.php
vendored
10
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
namespace Composer\Autoload;
|
namespace Composer\Autoload;
|
||||||
|
|
||||||
class ComposerStaticInit7ad2dfd941224dedfd9e69a3187017d8
|
class ComposerStaticInitc847eb2c7a922ed862fa0bfb18edd00b
|
||||||
{
|
{
|
||||||
public static $files = array (
|
public static $files = array (
|
||||||
'9b552a3cc426e3287cc811caefa3cf53' => __DIR__ . '/..' . '/topthink/think-helper/src/helper.php',
|
'9b552a3cc426e3287cc811caefa3cf53' => __DIR__ . '/..' . '/topthink/think-helper/src/helper.php',
|
||||||
@ -669,10 +669,10 @@ class ComposerStaticInit7ad2dfd941224dedfd9e69a3187017d8
|
|||||||
public static function getInitializer(ClassLoader $loader)
|
public static function getInitializer(ClassLoader $loader)
|
||||||
{
|
{
|
||||||
return \Closure::bind(function () use ($loader) {
|
return \Closure::bind(function () use ($loader) {
|
||||||
$loader->prefixLengthsPsr4 = ComposerStaticInit7ad2dfd941224dedfd9e69a3187017d8::$prefixLengthsPsr4;
|
$loader->prefixLengthsPsr4 = ComposerStaticInitc847eb2c7a922ed862fa0bfb18edd00b::$prefixLengthsPsr4;
|
||||||
$loader->prefixDirsPsr4 = ComposerStaticInit7ad2dfd941224dedfd9e69a3187017d8::$prefixDirsPsr4;
|
$loader->prefixDirsPsr4 = ComposerStaticInitc847eb2c7a922ed862fa0bfb18edd00b::$prefixDirsPsr4;
|
||||||
$loader->fallbackDirsPsr0 = ComposerStaticInit7ad2dfd941224dedfd9e69a3187017d8::$fallbackDirsPsr0;
|
$loader->fallbackDirsPsr0 = ComposerStaticInitc847eb2c7a922ed862fa0bfb18edd00b::$fallbackDirsPsr0;
|
||||||
$loader->classMap = ComposerStaticInit7ad2dfd941224dedfd9e69a3187017d8::$classMap;
|
$loader->classMap = ComposerStaticInitc847eb2c7a922ed862fa0bfb18edd00b::$classMap;
|
||||||
|
|
||||||
}, null, ClassLoader::class);
|
}, null, ClassLoader::class);
|
||||||
}
|
}
|
||||||
|
12
vendor/composer/installed.json
vendored
12
vendor/composer/installed.json
vendored
@ -958,17 +958,17 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "zoujingli/think-library",
|
"name": "zoujingli/think-library",
|
||||||
"version": "v6.0.13",
|
"version": "v6.0.14",
|
||||||
"version_normalized": "6.0.13.0",
|
"version_normalized": "6.0.14.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/zoujingli/ThinkLibrary.git",
|
"url": "https://github.com/zoujingli/ThinkLibrary.git",
|
||||||
"reference": "4f492966b363a613ec7e89af47db0c59fe322350"
|
"reference": "fd4e99d0ed04c87778cc47a3ca911cd1ef84a38b"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/4f492966b363a613ec7e89af47db0c59fe322350",
|
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/fd4e99d0ed04c87778cc47a3ca911cd1ef84a38b",
|
||||||
"reference": "4f492966b363a613ec7e89af47db0c59fe322350",
|
"reference": "fd4e99d0ed04c87778cc47a3ca911cd1ef84a38b",
|
||||||
"shasum": "",
|
"shasum": "",
|
||||||
"mirrors": [
|
"mirrors": [
|
||||||
{
|
{
|
||||||
@ -985,7 +985,7 @@
|
|||||||
"ext-mbstring": "*",
|
"ext-mbstring": "*",
|
||||||
"topthink/framework": "^6.0"
|
"topthink/framework": "^6.0"
|
||||||
},
|
},
|
||||||
"time": "2020-09-24T03:26:07+00:00",
|
"time": "2020-09-24T08:15:19+00:00",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
"extra": {
|
||||||
"think": {
|
"think": {
|
||||||
|
2
vendor/services.php
vendored
2
vendor/services.php
vendored
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// This file is automatically generated at:2020-09-24 13:05:54
|
// This file is automatically generated at:2020-09-24 16:20:22
|
||||||
declare (strict_types = 1);
|
declare (strict_types = 1);
|
||||||
return array (
|
return array (
|
||||||
0 => 'think\\admin\\Library',
|
0 => 'think\\admin\\Library',
|
||||||
|
@ -41,7 +41,7 @@ class Library extends Service
|
|||||||
/**
|
/**
|
||||||
* 扩展库版本号
|
* 扩展库版本号
|
||||||
*/
|
*/
|
||||||
const VERSION = '6.0.13';
|
const VERSION = '6.0.14';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动服务
|
* 启动服务
|
||||||
|
@ -64,8 +64,7 @@ class Database extends Command
|
|||||||
[$total, $used] = [count($tables = $this->getTables()), 0];
|
[$total, $used] = [count($tables = $this->getTables()), 0];
|
||||||
$this->setQueueProgress("总共需要修复 {$total} 张数据表", 0);
|
$this->setQueueProgress("总共需要修复 {$total} 张数据表", 0);
|
||||||
foreach ($tables as $table) {
|
foreach ($tables as $table) {
|
||||||
$stridx = progress_prefix($total, ++$used);
|
$this->queue->message($total, ++$used, "正在修复数据表 {$table}");
|
||||||
$this->setQueueProgress("[{$stridx}] 正在修复数据表 {$table}", $used / $total * 100);
|
|
||||||
$this->app->db->query("REPAIR TABLE `{$table}`");
|
$this->app->db->query("REPAIR TABLE `{$table}`");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,8 +82,7 @@ class Database extends Command
|
|||||||
[$total, $used] = [count($tables = $this->getTables()), 0];
|
[$total, $used] = [count($tables = $this->getTables()), 0];
|
||||||
$this->setQueueProgress("总共需要优化 {$total} 张数据表", 0);
|
$this->setQueueProgress("总共需要优化 {$total} 张数据表", 0);
|
||||||
foreach ($tables as $table) {
|
foreach ($tables as $table) {
|
||||||
$stridx = progress_prefix($total, ++$used);
|
$this->queue->message($total, ++$used, "正在优化数据表 {$table}");
|
||||||
$this->setQueueProgress("[{$stridx}] 正在优化数据表 {$table}", $used / $total * 100);
|
|
||||||
$this->app->db->query("OPTIMIZE TABLE `{$table}`");
|
$this->app->db->query("OPTIMIZE TABLE `{$table}`");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,16 +123,15 @@ class Install extends Command
|
|||||||
} else {
|
} else {
|
||||||
[$total, $used] = [count($data), 0];
|
[$total, $used] = [count($data), 0];
|
||||||
foreach ($data as $file) {
|
foreach ($data as $file) {
|
||||||
$prefix = progress_prefix($total, ++$used);
|
|
||||||
[$state, $mode, $name] = $module->updateFileByDownload($file);
|
[$state, $mode, $name] = $module->updateFileByDownload($file);
|
||||||
if ($state) {
|
if ($state) {
|
||||||
if ($mode === 'add') $this->output->writeln("[{$prefix}] --- {$name} add successfully");
|
if ($mode === 'add') $this->queue->message($total, ++$used, "--- {$name} add successfully");
|
||||||
if ($mode === 'mod') $this->output->writeln("[{$prefix}] --- {$name} update successfully");
|
if ($mode === 'mod') $this->queue->message($total, ++$used, "--- {$name} update successfully");
|
||||||
if ($mode === 'del') $this->output->writeln("[{$prefix}] --- {$name} delete successfully");
|
if ($mode === 'del') $this->queue->message($total, ++$used, "--- {$name} delete successfully");
|
||||||
} else {
|
} else {
|
||||||
if ($mode === 'add') $this->output->writeln("[{$prefix}] --- {$name} add failed");
|
if ($mode === 'add') $this->queue->message($total, ++$used, "--- {$name} add failed");
|
||||||
if ($mode === 'mod') $this->output->writeln("[{$prefix}] --- {$name} update failed");
|
if ($mode === 'mod') $this->queue->message($total, ++$used, "--- {$name} update failed");
|
||||||
if ($mode === 'del') $this->output->writeln("[{$prefix}] --- {$name} delete failed");
|
if ($mode === 'del') $this->queue->message($total, ++$used, "--- {$name} delete failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,12 +51,12 @@ class Queue extends Command
|
|||||||
public function configure()
|
public function configure()
|
||||||
{
|
{
|
||||||
$this->setName('xadmin:queue');
|
$this->setName('xadmin:queue');
|
||||||
$this->addArgument('action', Argument::OPTIONAL, 'stop|start|status|query|listen|clean|dorun|webstop|webstart|webstatus', 'listen');
|
|
||||||
$this->addArgument('code', Argument::OPTIONAL, 'Taskcode');
|
|
||||||
$this->addArgument('spts', Argument::OPTIONAL, 'Separator');
|
|
||||||
$this->addOption('host', '-H', Option::VALUE_OPTIONAL, 'The host of WebServer.');
|
$this->addOption('host', '-H', Option::VALUE_OPTIONAL, 'The host of WebServer.');
|
||||||
$this->addOption('port', '-p', Option::VALUE_OPTIONAL, 'The port of WebServer.');
|
$this->addOption('port', '-p', Option::VALUE_OPTIONAL, 'The port of WebServer.');
|
||||||
$this->addOption('daemon', 'd', Option::VALUE_NONE, 'Run the queue listen in daemon mode');
|
$this->addOption('daemon', 'd', Option::VALUE_NONE, 'Run the queue listen in daemon mode');
|
||||||
|
$this->addArgument('action', Argument::OPTIONAL, 'stop|start|status|query|listen|clean|dorun|webstop|webstart|webstatus', 'listen');
|
||||||
|
$this->addArgument('code', Argument::OPTIONAL, 'Taskcode');
|
||||||
|
$this->addArgument('spts', Argument::OPTIONAL, 'Separator');
|
||||||
$this->setDescription('Asynchronous Command Queue Task for ThinkAdmin');
|
$this->setDescription('Asynchronous Command Queue Task for ThinkAdmin');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,12 +189,11 @@ class Queue extends Command
|
|||||||
$this->app->db->name($this->table)->whereOr([$map1, $map2])->chunk(100, function (Collection $result) use ($total, &$loops, &$timeout) {
|
$this->app->db->name($this->table)->whereOr([$map1, $map2])->chunk(100, function (Collection $result) use ($total, &$loops, &$timeout) {
|
||||||
foreach ($result->toArray() as $item) {
|
foreach ($result->toArray() as $item) {
|
||||||
$item['loops_time'] > 0 ? $loops++ : $timeout++;
|
$item['loops_time'] > 0 ? $loops++ : $timeout++;
|
||||||
$prefix = progress_prefix($total, $timeout + $loops);
|
|
||||||
if ($item['loops_time'] > 0) {
|
if ($item['loops_time'] > 0) {
|
||||||
$this->setQueueProgress("[{$prefix}] 正在重置任务 {$item['code']} 为运行", ($timeout + $loops) * 100 / $total);
|
$this->queue->message($total, $timeout + $loops, "正在重置任务 {$item['code']} 为运行");
|
||||||
[$status, $message] = [1, intval($item['status']) === 4 ? '任务执行失败,已自动重置任务!' : '任务执行超时,已自动重置任务!'];
|
[$status, $message] = [1, intval($item['status']) === 4 ? '任务执行失败,已自动重置任务!' : '任务执行超时,已自动重置任务!'];
|
||||||
} else {
|
} else {
|
||||||
$this->setQueueProgress("[{$prefix}] 正在标记任务 {$item['code']} 为超时", ($timeout + $loops) * 100 / $total);
|
$this->queue->message($total, $timeout + $loops, "正在标记任务 {$item['code']} 为超时");
|
||||||
[$status, $message] = [4, '任务执行超时,已自动标识为失败!'];
|
[$status, $message] = [4, '任务执行超时,已自动标识为失败!'];
|
||||||
}
|
}
|
||||||
$this->app->db->name($this->table)->where(['id' => $item['id']])->update(['status' => $status, 'exec_desc' => $message]);
|
$this->app->db->name($this->table)->where(['id' => $item['id']])->update(['status' => $status, 'exec_desc' => $message]);
|
||||||
|
14
vendor/zoujingli/think-library/src/common.php
vendored
14
vendor/zoujingli/think-library/src/common.php
vendored
@ -282,18 +282,4 @@ if (!function_exists('down_file')) {
|
|||||||
$result = Storage::down($source, $force, $expire);
|
$result = Storage::down($source, $force, $expire);
|
||||||
return $result['url'] ?? $source;
|
return $result['url'] ?? $source;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!function_exists('progress_prefix')) {
|
|
||||||
/**
|
|
||||||
* 生成进度前缀文字
|
|
||||||
* @param integer $total
|
|
||||||
* @param integer $used
|
|
||||||
* @param string $char
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function progress_prefix(int $total, int $used, string $char = '0'): string
|
|
||||||
{
|
|
||||||
return str_pad("{$used}", strlen("{$total}"), $char, STR_PAD_LEFT) . "/{$total}";
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -194,6 +194,24 @@ class QueueService extends Service
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成进度前缀数据
|
||||||
|
* @param integer $total 记录总和
|
||||||
|
* @param integer $used 当前记录
|
||||||
|
* @param string $message 文字描述
|
||||||
|
*/
|
||||||
|
public function message(int $total, int $used, string $message = ''): void
|
||||||
|
{
|
||||||
|
$total = $total < 1 ? 1 : $total;
|
||||||
|
$prefix = str_pad("{$used}", strlen("{$total}"), '0', STR_PAD_LEFT);
|
||||||
|
$message = "[{$prefix}/{$total}] {$message}";
|
||||||
|
if (defined('WorkQueueCode')) {
|
||||||
|
$this->progress(2, $message, sprintf("%.2f", $used / $total * 100));
|
||||||
|
} else {
|
||||||
|
echo $message . PHP_EOL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行任务处理
|
* 执行任务处理
|
||||||
* @param array $data 任务参数
|
* @param array $data 任务参数
|
||||||
|
Loading…
x
Reference in New Issue
Block a user