fix add:一键清理辅种缓存、一键清理转移缓存、任务热刷新

This commit is contained in:
david 2021-02-06 01:17:14 +08:00
parent edc4984ec3
commit e13b84b51a
9 changed files with 144 additions and 21 deletions

View File

@ -147,7 +147,7 @@ class Api extends BaseController
} }
/** /**
* 清理缓存 * 清理系统级别的缓存、日志
* @param Request $request * @param Request $request
* @return Response * @return Response
*/ */

View File

@ -8,7 +8,6 @@ use app\common\Config as Conf;
use app\common\Constant; use app\common\Constant;
use app\domain\Config; use app\domain\Config;
use app\domain\Crontab; use app\domain\Crontab;
use app\domain\Reseed;
/** /**
* Class Status * Class Status
* @package app\controller * @package app\controller
@ -49,21 +48,20 @@ class Status extends BaseController
$system_info = sprintf('%s / %s', PHP_OS, PHP_OS_FAMILY); $system_info = sprintf('%s / %s', PHP_OS, PHP_OS_FAMILY);
//读取git信息 //读取git信息
$updated_at = get_current_git_filemtime() . (get_current_git_commit() ? ' (' . get_current_git_commit() . ')' : ''); $updated_at = get_current_git_filemtime() . (get_current_git_commit() ? ' (' . get_current_git_commit() . ')' : '');
$str = '<a href="https://github.com/ledccn/IYUUPlus/commits/master" target="_blank">%s</a>'; $updated_at = strlen($updated_at) > 10 ? $updated_at : '点此查看';
$updated_at = sprintf($str, strlen($updated_at) > 10 ? $updated_at : '点此查看');
$rs['data'] = [ $rs['data'] = [
'cron_total' => count($cron), 'cron_total' => count($cron),
'sites_total'=> count($user_sites), 'sites_total' => count($user_sites),
'sites_conut'=> count($sites), 'sites_conut' => count($sites),
'clients_total' => count($clients), 'clients_total' => count($clients),
'project' => iyuu_name(), 'project' => iyuu_name(),
'version' => $version, 'version' => $version,
'updated_at' => $updated_at, 'updated_at' => $updated_at,
'system_info' => $system_info, 'system_info' => $system_info,
'PHP_VERSION' => PHP_VERSION, 'PHP_VERSION' => PHP_VERSION,
'PHP_BINARY' => PHP_BINARY, 'PHP_BINARY' => PHP_BINARY,
'RUNTIME_PATH' => runtime_path(), 'RUNTIME_PATH' => runtime_path(),
]; ];
return json($rs); return json($rs);
} }

View File

@ -99,13 +99,51 @@ class Task extends BaseController
} }
/** /**
* 调试接口 * 清理任务缓存
* @param Request $request * @param Request $request
* @return Response * @return Response
*/ */
public function test(Request $request): Response public function clearCache(Request $request): Response
{ {
$rs = self::RS; $rs = self::RS;
$ret = false;
$clear_type = $request->get('type');
switch ($clear_type) {
case 'clearReseedCache':
$ret = domainReseed::clearReseedCache();
break;
case 'clearMoveCache':
$ret = domainReseed::clearMoveCache();
break;
default:
break;
}
$rs['data'] = [
'success' => $ret
];
return json($rs);
}
/**
* 刷新所有任务
* @descr 不同平台的配置会造成command错误需要重新解析命令
* @param Request $request
* @return Response
*/
public function refresh(Request $request): Response
{
$rs = self::RS;
$ret = true;
try {
Crontab::onWorkerStart();
} catch (\Exception $exception) {
$ret = false;
}
$rs['data'] = [
'success' => $ret
];
return json($rs); return json($rs);
} }
} }

View File

@ -3,6 +3,8 @@ namespace app\domain;
use app\common\Config as Conf; use app\common\Config as Conf;
use app\common\Constant; use app\common\Constant;
use IYUU\Library\IFile;
/** /**
* 辅种相关 * 辅种相关
* Class Reseed * Class Reseed
@ -57,4 +59,42 @@ class Reseed
return $rs; return $rs;
} }
/**
* 获取辅种缓存的存放路径
* @return string
*/
public static function getReseedCachePath():string
{
return runtime_path() . DIRECTORY_SEPARATOR . 'torrent' . DIRECTORY_SEPARATOR . 'cachehash';
}
/**
* 获取转移缓存的存放路径
* @return string
*/
public static function getMoveCachePath():string
{
return runtime_path() . DIRECTORY_SEPARATOR . 'torrent' . DIRECTORY_SEPARATOR . 'cachemove';
}
/**
* 清理辅种缓存
* @return bool
*/
public static function clearReseedCache():bool
{
$dir = self::getReseedCachePath();
return IFile::rmdir($dir, true);
}
/**
* 清理转移缓存
* @return bool
*/
public static function clearMoveCache():bool
{
$dir = self::getMoveCachePath();
return IFile::rmdir($dir, true);
}
} }

View File

@ -30,9 +30,7 @@ echo microtime(true).' composer依赖载入完成'.PHP_EOL;
// 定义目录 // 定义目录
defined('ROOT_PATH') or define('ROOT_PATH', __DIR__); defined('ROOT_PATH') or define('ROOT_PATH', __DIR__);
defined('DB_PATH') or define('DB_PATH', __DIR__ . DIRECTORY_SEPARATOR . 'db');
defined('RUNTIME_PATH') or define('RUNTIME_PATH', __DIR__ . DIRECTORY_SEPARATOR . 'runtime'); defined('RUNTIME_PATH') or define('RUNTIME_PATH', __DIR__ . DIRECTORY_SEPARATOR . 'runtime');
defined('CRONATB_PATH') or define('CRONATB_PATH', RUNTIME_PATH . DIRECTORY_SEPARATOR . 'crontab');
defined('TORRENT_PATH') or define('TORRENT_PATH', RUNTIME_PATH . DIRECTORY_SEPARATOR . 'torrent'); defined('TORRENT_PATH') or define('TORRENT_PATH', RUNTIME_PATH . DIRECTORY_SEPARATOR . 'torrent');
defined('DS') or define('DS', DIRECTORY_SEPARATOR); defined('DS') or define('DS', DIRECTORY_SEPARATOR);

View File

@ -167,6 +167,15 @@
{{# } }} {{# } }}
</script> </script>
<!-- 模板表格头工具栏 -->
<script type="text/html" id="tableTopToolbar">
<div class="layui-btn-container">
<button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="clearReseedCache">清理辅种缓存</button>
<button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="clearMoveCache">清理转移缓存</button>
<button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="refreshCrontab">刷新任务</button>
</div>
</script>
<!-- 模板表格行工具条 --> <!-- 模板表格行工具条 -->
<script type="text/html" id="tableToolbar"> <script type="text/html" id="tableToolbar">
<span class="layui-badge layui-bg-cyan" lay-event="run">运行</span> <span class="layui-badge layui-bg-cyan" lay-event="run">运行</span>
@ -301,6 +310,12 @@
table.render({ table.render({
elem: '#tableId' elem: '#tableId'
,url: API.tableList ,url: API.tableList
,toolbar: '#tableTopToolbar'
,defaultToolbar: ['filter', 'print', {
title: '提示'
,layEvent: 'LAYTABLE_TIPS'
,icon: 'layui-icon-tips'
}]
,parseData: function(res){ ,parseData: function(res){
return { return {
"code": res.ret === 200 ? 0 : res.ret, "code": res.ret === 200 ? 0 : res.ret,
@ -379,6 +394,38 @@
,limit:500 ,limit:500
}); });
/**
* 监听头工具栏事件
*/
table.on('toolbar(tableFilter)', function(obj){
let checkStatus = table.checkStatus(obj.config.id);
let data = checkStatus.data;
switch(obj.event){
case 'clearReseedCache':
case 'clearMoveCache':
$.getJSON('/Task/clearCache', {'type': obj.event}, function (d) {
if (d.ret === 200) {
layer.msg(d.data.success ? '清理成功' : '清理失败');
return;
}
layer.msg('接口请求失败:/Task/clearCache');
});
break;
case 'refreshCrontab':
$.getJSON('/Task/refresh', function (d) {
if (d.ret === 200) {
layer.msg(d.data.success ? '全部任务刷新成功' : '任务刷新失败');
return;
}
layer.msg('接口请求失败:/Task/refresh');
});
break;
case 'LAYTABLE_TIPS':
layer.alert('这是工具栏右侧自定义的一个图标按钮');
break;
};
});
/** /**
* 监听行工具条 * 监听行工具条
*/ */

View File

@ -207,7 +207,7 @@
</tr> </tr>
<tr> <tr>
<td>最后更新</td> <td>最后更新</td>
<td id="updated_at"></td> <td><a href="https://github.com/ledccn/IYUUPlus/commits/master" target="_blank" id="updated_at"></a></td>
</tr> </tr>
<tr> <tr>
<td>系统环境</td> <td>系统环境</td>

View File

@ -60,6 +60,7 @@ class IFile
/** /**
* @brief 清空目录下的所有文件 * @brief 清空目录下的所有文件
* @param string $dir
* @return bool false:失败; true:成功; * @return bool false:失败; true:成功;
*/ */
public static function clearDir($dir) public static function clearDir($dir)

View File

@ -1,8 +1,9 @@
## TODO清单 ## TODO清单
- [ ] 辅种结束,写结束日志 - [ ] 辅种结束,写结束日志
- [ ] 一键清理辅种缓存 - [x] 一键清理辅种缓存
- [ ] 一键清理转移缓存 - [x] 一键清理转移缓存
- [x] 任务热刷新
- [ ] [站点设置]已添加的,屏蔽选择 - [ ] [站点设置]已添加的,屏蔽选择
- [ ] 前端实时显示任务运行状态Ajax - [ ] 前端实时显示任务运行状态Ajax
- [ ] 一键更新到最新版 - [ ] 一键更新到最新版