[更新]修改系统任务

This commit is contained in:
Anyon 2019-08-21 15:15:03 +08:00
parent 9546b9a668
commit 4bc8726015
3 changed files with 46 additions and 7 deletions

View File

@ -17,6 +17,7 @@ namespace app\admin\controller;
use library\Controller;
use think\Console;
use think\exception\HttpResponseException;
/**
* 系统系统任务
@ -50,6 +51,7 @@ class Queue extends Controller
$this->message = $exception->getMessage();
}
$this->title = '系统任务管理';
$this->iswin = PATH_SEPARATOR === ';';
$query = $this->_query($this->table)->dateBetween('create_at,end_at');
$query->like('title,preload')->equal('status')->order('id desc')->page();
}
@ -65,6 +67,36 @@ class Queue extends Controller
$this->_save($this->table, ['status' => '1']);
}
/**
* (WIN)创建任务监听进程
* @auth true
*/
public function processStart()
{
try {
$this->success(nl2br(Console::call('xtask:start')->fetch()));
} catch (HttpResponseException $exception) {
throw $exception;
} catch (\Exception $e) {
$this->error($e->getMessage());
}
}
/**
* (WIN)停止任务监听进程
* @auth true
*/
public function processStop()
{
try {
$this->success(nl2br(Console::call('xtask:stop')->fetch()));
} catch (HttpResponseException $exception) {
throw $exception;
} catch (\Exception $e) {
$this->error($e->getMessage());
}
}
/**
* 删除系统任务
* @auth true

View File

@ -87,14 +87,13 @@ if (!function_exists('sysqueue')) {
$result = Db::name('SystemQueue')->insert([
'title' => $title, 'preload' => $loade,
'data' => json_encode($data, JSON_UNESCAPED_UNICODE),
'time' => ($later > 0 ? time() + $later : time()) - 3,
'double' => intval($double),
'time' => $later > 0 ? time() + $later : time(),
'double' => intval($double), 'create_at' => date('Y-m-d H:i:s'),
]);
return $result !== false;
}
}
if (!function_exists('local_image')) {
/**
* 下载远程文件到本地

View File

@ -2,8 +2,16 @@
{block name="button"}
{if auth("admin/queue/remove")}
<button data-action='{:url("remove")}' data-confirm="确定要删除这些任务吗?" data-rule="id#{key}" class='layui-btn layui-btn-sm layui-btn-primary'>删除任务</button>
{if auth("remove")}
<button data-action='{:url("remove")}' data-confirm="确定要删除这些任务吗?" data-rule="id#{key}" class='layui-btn layui-btn-sm layui-btn-primary'>删除任务记录</button>
{/if}
{if auth("processstart") && $iswin}
<button data-load='{:url("processstart")}' class='layui-btn layui-btn-sm layui-btn-primary'>创建监听进程</button>
{/if}
{if auth("processstop") && $iswin}
<button data-load='{:url("processstop")}' class='layui-btn layui-btn-sm layui-btn-primary'>停止监听进程</button>
{/if}
{/block}
@ -36,8 +44,8 @@
<span class="color-desc">任务指令:{$vo.preload}</span>
</td>
<td class='text-left nowrap'>
创建时间:{$vo.create_at|format_datetime|raw}<br>
跟进时间:{$vo.end_at|format_datetime|raw}
创建时间:{$vo.create_at|format_datetime} / {$vo.time|format_datetime}<br>
执行时间:{$vo.start_at|format_datetime} / {$vo.end_at|format_datetime}
</td>
<td class='text-left nowrap'>
任务状态:{eq name='vo.double' value='1'}