mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
修改任务加载机制
任务统计改为异步处理。 1. 修改 layui.table 数据 filter。 2. 修改 ThinkLibrary 分页增加回调参数。 3. 修改 任务模块 模板及控制器,改为callback
This commit is contained in:
parent
7c0c76ac31
commit
e67191d610
@ -54,20 +54,32 @@ class Queue extends Controller
|
|||||||
$this->command = "sudo -u {$_SERVER['USER']} {$process->think('xadmin:queue start')}";
|
$this->command = "sudo -u {$_SERVER['USER']} {$process->think('xadmin:queue start')}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 任务状态统计
|
|
||||||
$this->total = ['dos' => 0, 'pre' => 0, 'oks' => 0, 'ers' => 0];
|
|
||||||
SystemQueue::mk()->field('status,count(1) count')->group('status')->select()->map(function ($item) {
|
|
||||||
if ($item['status'] === 1) $this->total['pre'] = $item['count'];
|
|
||||||
if ($item['status'] === 2) $this->total['dos'] = $item['count'];
|
|
||||||
if ($item['status'] === 3) $this->total['oks'] = $item['count'];
|
|
||||||
if ($item['status'] === 4) $this->total['ers'] = $item['count'];
|
|
||||||
});
|
|
||||||
}, function (QueryHelper $query) {
|
}, function (QueryHelper $query) {
|
||||||
$query->equal('status')->like('code,title,command');
|
$query->equal('status')->like('code,title,command');
|
||||||
$query->timeBetween('enter_time,exec_time')->dateBetween('create_at');
|
$query->timeBetween('enter_time,exec_time')->dateBetween('create_at');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页数据回调处理
|
||||||
|
* @param array $data
|
||||||
|
* @param array $result
|
||||||
|
* @return void
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
protected function _index_page_filter(array $data, array &$result)
|
||||||
|
{
|
||||||
|
$result['extra'] = ['dos' => 0, 'pre' => 0, 'oks' => 0, 'ers' => 0];
|
||||||
|
SystemQueue::mk()->field('status,count(1) count')->group('status')->select()->map(function ($item) use (&$result) {
|
||||||
|
if ($item['status'] === 1) $result['extra']['pre'] = $item['count'];
|
||||||
|
if ($item['status'] === 2) $result['extra']['dos'] = $item['count'];
|
||||||
|
if ($item['status'] === 3) $result['extra']['oks'] = $item['count'];
|
||||||
|
if ($item['status'] === 4) $result['extra']['ers'] = $item['count'];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重启系统任务
|
* 重启系统任务
|
||||||
* @auth true
|
* @auth true
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
<b data-tips-text="点击可复制【任务服务启动指令】" class="layui-icon pointer margin-right-20" data-copy="{$command|default=''}"></b>
|
<b data-tips-text="点击可复制【任务服务启动指令】" class="layui-icon pointer margin-right-20" data-copy="{$command|default=''}"></b>
|
||||||
<script>$('[data-queue-message]').load('{:sysuri("admin/api.queue/status")}');</script>
|
<script>$('[data-queue-message]').load('{:sysuri("admin/api.queue/status")}');</script>
|
||||||
<!--{/if}-->
|
<!--{/if}-->
|
||||||
<b>任务统计:</b>待处理 <b class="color-text">{$total.pre|default=0}</b> 个任务,处理中 <b class="color-blue">{$total.dos|default=0}</b> 个任务,已完成 <b class="color-green">{$total.oks|default=0}</b> 个任务,已失败 <b class="color-red">{$total.ers|default=0}</b> 个任务。
|
<b>任务统计:</b>待处理 <b class="color-text" data-extra="pre">{$total.pre|default=0}</b> 个任务,处理中 <b class="color-blue" data-extra="dos">{$total.dos|default=0}</b> 个任务,已完成 <b class="color-green" data-extra="oks">{$total.oks|default=0}</b> 个任务,已失败 <b class="color-red" data-extra="ers">{$total.ers|default=0}</b> 个任务。
|
||||||
</div>
|
</div>
|
||||||
<div class="think-box-shadow">
|
<div class="think-box-shadow">
|
||||||
{include file='queue/index_search'}
|
{include file='queue/index_search'}
|
||||||
@ -53,8 +53,13 @@
|
|||||||
<script>
|
<script>
|
||||||
$(function () {
|
$(function () {
|
||||||
$('#QueueTable').layTable({
|
$('#QueueTable').layTable({
|
||||||
height: 'full',
|
even: true, height: 'full',
|
||||||
even: true, sort: {field: 'loops_time desc,id', type: 'desc'},
|
sort: {field: 'loops_time desc,id', type: 'desc'},
|
||||||
|
filter: function (items, result) {
|
||||||
|
return result && result.extra && $('[data-extra]').map(function () {
|
||||||
|
this.innerHTML = result.extra[this.dataset.extra] || 0;
|
||||||
|
}), items;
|
||||||
|
},
|
||||||
cols: [[
|
cols: [[
|
||||||
{checkbox: true, fixed: 'left'},
|
{checkbox: true, fixed: 'left'},
|
||||||
{
|
{
|
||||||
|
@ -694,7 +694,7 @@ $(function () {
|
|||||||
layui.sessionData('pages', {key: table.id, value: this.page.curr || 1}), (table.loading = true);
|
layui.sessionData('pages', {key: table.id, value: this.page.curr || 1}), (table.loading = true);
|
||||||
$table.next().find('[data-load],[data-queue],[data-action],[data-iframe]').not('[data-table-id]').attr('data-table-id', table.id);
|
$table.next().find('[data-load],[data-queue],[data-action],[data-iframe]').not('[data-table-id]').attr('data-table-id', table.id);
|
||||||
}, option.parseData = function (res) {
|
}, option.parseData = function (res) {
|
||||||
if (typeof params.filter === 'function') res.data = params.filter(res.data);
|
if (typeof params.filter === 'function') res.data = params.filter(res.data, res);
|
||||||
var maxp = Math.ceil(res.count / table.limit), curp = layui.sessionData('pages')[option.id] || 1;
|
var maxp = Math.ceil(res.count / table.limit), curp = layui.sessionData('pages')[option.id] || 1;
|
||||||
if (curp > maxp && curp > 1) table.elem.trigger('reload', {page: {curr: maxp}});
|
if (curp > maxp && curp > 1) table.elem.trigger('reload', {page: {curr: maxp}});
|
||||||
return res;
|
return res;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user