mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-11-30 10:58:14 +08:00
构建历史支持配置单个构建最多保存多少个历史
This commit is contained in:
parent
d9e128f673
commit
766df665fc
@ -14,6 +14,7 @@
|
||||
2. 解决菜单路径不正确问题(GITEE@I15O46)
|
||||
3. 【Agent】 windows中Agent关闭,Agent中所有项目跟随关闭(感谢@java gods)
|
||||
4. 【Server】构建命令包含删除命令误判断(感谢@Sawyer)
|
||||
5. 【Server】构建历史支持配置单个构建最多保存多少个历史
|
||||
|
||||
-----------------------------------------------------------
|
||||
|
||||
|
@ -98,10 +98,15 @@ public class DbBuildHistoryLogService extends BaseDbLogService<BuildHistoryLog>
|
||||
@Override
|
||||
public void insert(BuildHistoryLog buildHistoryLog) {
|
||||
super.insert(buildHistoryLog);
|
||||
// 清理数据
|
||||
DbConfig.autoClear(getTableName(), "startTime", ServerExtConfigBean.getBuildMaxHistoryCount(), aLong -> {
|
||||
doClearPage(1, aLong);
|
||||
});
|
||||
// 清理总数据
|
||||
int buildMaxHistoryCount = ServerExtConfigBean.getInstance().getBuildMaxHistoryCount();
|
||||
DbConfig.autoClear(getTableName(), "startTime", buildMaxHistoryCount,
|
||||
aLong -> doClearPage(1, aLong));
|
||||
// 清理单个
|
||||
int buildItemMaxHistoryCount = ServerExtConfigBean.getInstance().getBuildItemMaxHistoryCount();
|
||||
DbConfig.autoClear(getTableName(), "startTime", buildItemMaxHistoryCount,
|
||||
entity -> entity.set("buildDataId", buildHistoryLog.getBuildDataId()),
|
||||
aLong -> doClearPage(1, aLong));
|
||||
}
|
||||
|
||||
private void doClearPage(int pageNo, long time) {
|
||||
|
@ -48,12 +48,16 @@ public class ServerExtConfigBean {
|
||||
private String authorizeToken;
|
||||
|
||||
/**
|
||||
* 构建最多报错多少份历史记录
|
||||
* 构建最多保存多少份历史记录
|
||||
*/
|
||||
@Value("${build.maxHistoryCount:50}")
|
||||
@Value("${build.maxHistoryCount:1000}")
|
||||
private int buildMaxHistoryCount;
|
||||
|
||||
|
||||
@Value("${build.itemMaxHistoryCount:50}")
|
||||
private int buildItemMaxHistoryCount;
|
||||
|
||||
|
||||
public String getAuthorizeToken() {
|
||||
return authorizeToken;
|
||||
}
|
||||
@ -70,8 +74,12 @@ public class ServerExtConfigBean {
|
||||
return h2DbLogStorageCount;
|
||||
}
|
||||
|
||||
public static int getBuildMaxHistoryCount() {
|
||||
return getInstance().buildMaxHistoryCount;
|
||||
public int getBuildMaxHistoryCount() {
|
||||
return buildMaxHistoryCount;
|
||||
}
|
||||
|
||||
public int getBuildItemMaxHistoryCount() {
|
||||
return buildItemMaxHistoryCount;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,6 +61,9 @@ public class DbConfig {
|
||||
* @param timeClo 时间字段名
|
||||
*/
|
||||
public static void autoClear(String tableName, String timeClo) {
|
||||
if (ServerExtConfigBean.getInstance().getH2DbLogStorageCount() <= 0) {
|
||||
return;
|
||||
}
|
||||
autoClear(tableName, timeClo, ServerExtConfigBean.getInstance().getH2DbLogStorageCount(), time -> {
|
||||
Entity entity = Entity.create(tableName);
|
||||
entity.set(timeClo, "< " + time);
|
||||
@ -74,6 +77,11 @@ public class DbConfig {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static void autoClear(String tableName, String timeClo, int maxCount, Consumer<Long> consumer) {
|
||||
autoClear(tableName, timeClo, maxCount, null, consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动清理数据接口
|
||||
*
|
||||
@ -82,12 +90,13 @@ public class DbConfig {
|
||||
* @param maxCount 最大数量
|
||||
* @param consumer 查询出超过范围的时间回调
|
||||
*/
|
||||
public static void autoClear(String tableName, String timeClo, int maxCount, Consumer<Long> consumer) {
|
||||
if (ServerExtConfigBean.getInstance().getH2DbLogStorageCount() <= 0) {
|
||||
return;
|
||||
}
|
||||
public static void autoClear(String tableName, String timeClo, int maxCount, Consumer<Entity> whereCon, Consumer<Long> consumer) {
|
||||
ThreadUtil.execute(() -> {
|
||||
Entity entity = Entity.create(tableName);
|
||||
if (whereCon != null) {
|
||||
// 条件
|
||||
whereCon.accept(entity);
|
||||
}
|
||||
Page page = new Page(maxCount, 1);
|
||||
page.addOrder(new Order(timeClo, Direction.DESC));
|
||||
PageResult<Entity> pageResult;
|
||||
|
@ -27,4 +27,6 @@ db:
|
||||
# 构建相关配置
|
||||
build:
|
||||
# 最多保存多少份历史记录
|
||||
maxHistoryCount: 50
|
||||
maxHistoryCount: 1000
|
||||
# 单个最多保存多少份历史记录
|
||||
buildItemMaxHistoryCount: 50
|
Loading…
Reference in New Issue
Block a user