增加任务记录清理操作

This commit is contained in:
Anyon 2020-01-06 16:42:05 +08:00
parent 77feb27dc1
commit d97b0a248e
2 changed files with 32 additions and 2 deletions

View File

@ -97,7 +97,11 @@ class Queue extends Controller
{
try {
$message = nl2br($this->app->console->call('xtask:start')->fetch());
preg_match('/主进程\d+/', $message, $attr) ? $this->success($message) : $this->error($message);
if (preg_match('/process.*?\d+/', $message, $attr)) {
$this->success('任务监听主进程启动成功!');
} else {
$this->error($message);
}
} catch (HttpResponseException $exception) {
throw $exception;
} catch (\Exception $e) {
@ -105,6 +109,22 @@ class Queue extends Controller
}
}
/**
* 清理3天前的记录
* @auth true
* @throws \think\db\exception\DbException
*/
public function clear()
{
$map = [['exec_time', '<', strtotime('-3days')]];
$result = $this->app->db->name($this->table)->where($map)->delete();
if ($result !== false) {
$this->success('成功清理3天前的任务记录');
} else {
$this->error('清理3天前的任务记录失败');
}
}
/**
* WIN停止监听进程
* @auth true
@ -113,7 +133,13 @@ class Queue extends Controller
{
try {
$message = nl2br($this->app->console->call('xtask:stop')->fetch());
stripos($message, '成功') !== false ? $this->success($message) : $this->error($message);
if (stripos($message, 'succeeded')) {
$this->success('停止任务监听主进程成功!');
} elseif (stripos($message, 'finish')) {
$this->success('没有找到需要停止的进程!');
} else {
$this->error($message);
}
} catch (HttpResponseException $exception) {
throw $exception;
} catch (\Exception $e) {

View File

@ -14,6 +14,10 @@
<button data-action='{:url("remove")}' data-rule="id#{key}" data-confirm="确定批量删除任务吗?" class='layui-btn layui-btn-sm layui-btn-primary'>批量删除</button>
{/if}
{if auth("clear")}
<button data-load='{:url("clear")}' data-confirm="确定要清理3天前的任务记录吗" class='layui-btn layui-btn-sm layui-btn-primary'>清理记录</button>
{/if}
{/block}
{block name="content"}