Skip to content

Commit

Permalink
日志清理功能
Browse files Browse the repository at this point in the history
  • Loading branch information
xueli.xue committed May 8, 2017
1 parent 882d7a4 commit 00cd63c
Show file tree
Hide file tree
Showing 17 changed files with 205 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -813,15 +813,15 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 3、执行器,server启动、销毁和注册逻辑调整;
- 4、JettyServer关闭逻辑优化,修复执行器无法正常关闭导致端口占用和频繁打印c3p0日志的问题;
- 5、JobHandler中开启子线程时,支持子线程输出执行日志并通过Rolling查看。
- 6、任务日志清理功能;
#### TODO LIST
- 1、任务并行触发处理规则:单机串行队列(默认)、单机并行、串行忽略、单机覆盖;
- 2、任务权限管理;
- 3、调度失败重试机制;
- 4、执行器与数据库解耦,只需配置调度中心集群地址即可(与当前通过JDBC注册自动发现方式,相冲突,待考虑);
- 5、任务日志定期清理功能,支持设置日志上限;
- 6、任务分片:一个任务被拆分成N个独立的任务单元,然后由分布式部署的执行器分别执行某一个或几个分片单元;
- 7、任务分片路由:分片采用一致性Hash算法计算出尽量稳定的分片顺序,即使注册机器存在波动也不会引起分批分片顺序大的波动;
- 5、任务分片:一个任务被拆分成N个独立的任务单元,然后由分布式部署的执行器分别执行某一个或几个分片单元;
- 6、任务分片路由:分片采用一致性Hash算法计算出尽量稳定的分片顺序,即使注册机器存在波动也不会引起分批分片顺序大的波动;
## 七、其他
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,37 @@ public ReturnT<String> logKill(int id){
return new ReturnT<String>(500, runResult.getMsg());
}
}

@RequestMapping("/clearLog")
@ResponseBody
public ReturnT<String> clearLog(int jobGroup, int jobId, int type){

Date clearBeforeTime = null;
int clearBeforeNum = 0;
if (type == 1) {
clearBeforeTime = DateUtils.addMonths(new Date(), -1); // 清理一个月之前日志数据
} else if (type == 2) {
clearBeforeTime = DateUtils.addMonths(new Date(), -3); // 清理三个月之前日志数据
} else if (type == 3) {
clearBeforeTime = DateUtils.addMonths(new Date(), -6); // 清理六个月之前日志数据
} else if (type == 4) {
clearBeforeTime = DateUtils.addYears(new Date(), -1); // 清理一年之前日志数据
} else if (type == 5) {
clearBeforeNum = 1000; // 清理一千条以前日志数据
} else if (type == 6) {
clearBeforeNum = 10000; // 清理一万条以前日志数据
} else if (type == 7) {
clearBeforeNum = 30000; // 清理三万条以前日志数据
} else if (type == 8) {
clearBeforeNum = 100000; // 清理十万条以前日志数据
} else if (type == 9) {
clearBeforeNum = 0; // 清理所用日志数据
} else {
return new ReturnT<String>(ReturnT.FAIL_CODE, "清理类型参数异常");
}

xxlJobLogDao.clearLog(jobGroup, jobId, clearBeforeTime, clearBeforeNum);
return ReturnT.SUCCESS;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ public interface IXxlJobLogDao {

public List<Map<String, Object>> triggerCountByDay(Date from, Date to, int handleCode);

public int clearLog(int jobGroup, int jobId, Date clearBeforeTime, int clearBeforeNum);

}
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,14 @@ public List<Map<String, Object>> triggerCountByDay(Date from, Date to, int handl
return sqlSessionTemplate.selectList("XxlJobLogMapper.triggerCountByDay", params);
}

@Override
public int clearLog(int jobGroup, int jobId, Date clearBeforeTime, int clearBeforeNum) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("jobGroup", jobGroup);
params.put("jobId", jobId);
params.put("clearBeforeTime", clearBeforeTime);
params.put("clearBeforeNum", clearBeforeNum);
return sqlSessionTemplate.delete("XxlJobLogMapper.clearLog", params);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,37 @@
</if>
GROUP BY triggerDay;
</select>

<delete id="clearLog" parameterType="java.util.Map" >
delete from XXL_JOB_QRTZ_TRIGGER_LOG
<trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="jobGroup gt 0">
AND job_group = #{jobGroup}
</if>
<if test="jobId gt 0">
AND job_id = #{jobId}
</if>
<if test="clearBeforeTime != null">
AND trigger_time <![CDATA[ <= ]]> #{clearBeforeTime}
</if>
<if test="clearBeforeNum gt 0">
AND id NOT in(
SELECT id FROM(
SELECT id FROM XXL_JOB_QRTZ_TRIGGER_LOG AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="jobGroup gt 0">
AND t.job_group = #{jobGroup}
</if>
<if test="jobId gt 0">
AND t.job_id = #{jobId}
</if>
</trim>
ORDER BY t.trigger_time desc
LIMIT 0, #{clearBeforeNum}
) t1
)
</if>
</trim>
</delete>

</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
<#-- jquery cookie -->
<script src="${request.contextPath}/static/plugins/jquery/jquery.cookie.js"></script>

<#-- layer -->
<script src="${request.contextPath}/static/plugins/layer/layer.js"></script>

<#-- common -->
<script src="${request.contextPath}/static/js/xxl.alert.1.js"></script>
<script src="${request.contextPath}/static/js/common.1.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<div class="input-group">
<span class="input-group-addon">执行器</span>
<select class="form-control" id="jobGroup" paramVal="<#if jobInfo?exists>${jobInfo.jobGroup}</#if>" >
<option value="0" >请选择</option>
<option value="0" >全部</option>
<#list JobGroupList as group>
<option value="${group.id}" >${group.title}</option>
</#list>
Expand All @@ -47,7 +47,7 @@
<div class="input-group">
<span class="input-group-addon">任务</span>
<select class="form-control" id="jobId" paramVal="<#if jobInfo?exists>${jobInfo.id}</#if>" >
<option value="0" >请选择</option>
<option value="0" >全部</option>
</select>
</div>
</div>
Expand All @@ -59,10 +59,13 @@
<input type="text" class="form-control" id="filterTime" readonly >
</div>
</div>
<div class="col-xs-2">
<button class="btn btn-block btn-info" id="searchBtn">搜索</button>
<div class="col-xs-1">
<button class="btn btn-block btn-info" id="searchBtn">搜索</button>
</div>
<div class="col-xs-1">
<button class="btn btn-block btn-nomal" id="clearLog">清理</button>
</div>
</div>
Expand Down Expand Up @@ -102,6 +105,61 @@
<@netCommon.commonFooter />
</div>

<!-- 日志清理.模态框 -->
<div class="modal fade" id="clearLogModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" >日志清理</h4>
</div>
<div class="modal-body">
<form class="form-horizontal form" role="form" >
<div class="form-group">
<label class="col-sm-3 control-label"">执行器:</label>
<div class="col-sm-9">
<input type="text" class="form-control jobGroupText" readonly >
<input type="hidden" name="jobGroup" >
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"">任务:</label>
<div class="col-sm-9">
<input type="text" class="form-control jobIdText" readonly >
<input type="hidden" name="jobId" >
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"">清理类型:</label>
<div class="col-sm-9">
<select class="form-control" name="type" >
<option value="1" >清理一个月之前日志数据</option>
<option value="2" >清理三个月之前日志数据</option>
<option value="3" >清理六个月之前日志数据</option>
<option value="4" >清理一年之前日志数据</option>
<option value="5" >清理一千条以前日志数据</option>
<option value="6" >清理一万条以前日志数据</option>
<option value="7" >清理三万条以前日志数据</option>
<option value="8" >清理十万条以前日志数据</option>
<option value="9" >清理所用日志数据</option>
</select>
</div>
</div>
<hr>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-6">
<button type="button" class="btn btn-primary ok" >保存</button>
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<@netCommon.commonScript />
<!-- DataTables -->
<script src="${request.contextPath}/static/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
Expand Down
56 changes: 52 additions & 4 deletions xxl-job-admin/src/main/webapp/static/js/joblog.index.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $(function() {
dataType : "json",
success : function(data){
if (data.code == 200) {
$("#jobId").html('<option value="0" >请选择</option>');
$("#jobId").html('<option value="0" >全部</option>');
$.each(data.content, function (n, value) {
$("#jobId").append('<option value="' + value.id + '" >' + value.jobDesc + '</option>');
});
Expand Down Expand Up @@ -153,7 +153,7 @@ $(function() {
if (row.triggerCode == 200){
var temp = '<a href="javascript:;" class="logDetail" _id="'+ row.id +'">执行日志</a>';
if(row.handleCode == 0){
temp += '<br><a href="javascript:;" class="logKill" _id="'+ row.id +'">终止任务</a>';
temp += '<br><a href="javascript:;" class="logKill" _id="'+ row.id +'" style="color: red;" >终止任务</a>';
}
return temp;
}
Expand Down Expand Up @@ -228,7 +228,10 @@ $(function() {
});
*/
});


/**
* 终止任务
*/
$('#joblog_list').on('click', '.logKill', function(){
var _id = $(this).attr('_id');
ComConfirm.show("确认主动终止任务?", function(){
Expand All @@ -248,5 +251,50 @@ $(function() {
});
});
});


/**
* 清理任务Log
*/
$('#clearLog').on('click', function(){

var jobGroup = $('#jobGroup').val();
var jobId = $('#jobId').val();

var jobGroupText = $("#jobGroup").find("option:selected").text();
var jobIdText = $("#jobId").find("option:selected").text();

$('#clearLogModal input[name=jobGroup]').val(jobGroup);
$('#clearLogModal input[name=jobId]').val(jobId);

$('#clearLogModal .jobGroupText').val(jobGroupText);
$('#clearLogModal .jobIdText').val(jobIdText);

$('#clearLogModal').modal('show');

});
$("#clearLogModal .ok").on('click', function(){
$.post(base_url + "/joblog/clearLog", $("#clearLogModal .form").serialize(), function(data, status) {
if (data.code == "200") {
$('#clearLogModal').modal('hide');
layer.open({
title: '系统提示',
content: '日志清理成功',
icon: '1',
end: function(layero, index){
logTable.fnDraw();
}
});
} else {
layer.open({
title: '系统提示',
content: (data.msg || "日志清理失败"),
icon: '2'
});
}
});
});
$("#clearLogModal").on('hide.bs.modal', function () {
$("#clearLogModal .form")[0].reset();
});

});
2 changes: 2 additions & 0 deletions xxl-job-admin/src/main/webapp/static/plugins/layer/layer.js

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 00cd63c

Please sign in to comment.