feat: 添加设备冷却逻辑,过滤冷却期内设备并处理冷却队列
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package com.gameplatform.server.task;
|
||||
|
||||
import com.gameplatform.server.service.cooldown.MachineCooldownService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 机器冷却清理任务
|
||||
* 定期清理过期的机器冷却记录以释放内存
|
||||
*/
|
||||
@Component
|
||||
public class MachineCooldownCleanupTask {
|
||||
private static final Logger log = LoggerFactory.getLogger(MachineCooldownCleanupTask.class);
|
||||
|
||||
private final MachineCooldownService machineCooldownService;
|
||||
|
||||
public MachineCooldownCleanupTask(MachineCooldownService machineCooldownService) {
|
||||
this.machineCooldownService = machineCooldownService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 每30分钟清理一次过期的冷却记录
|
||||
*/
|
||||
@Scheduled(fixedRate = 30 * 60 * 1000) // 30分钟
|
||||
public void cleanupExpiredCooldowns() {
|
||||
try {
|
||||
int sizeBefore = machineCooldownService.getCooldownQueueSize();
|
||||
machineCooldownService.cleanupExpiredCooldowns();
|
||||
int sizeAfter = machineCooldownService.getCooldownQueueSize();
|
||||
|
||||
if (sizeBefore != sizeAfter) {
|
||||
log.info("机器冷却记录清理完成: 清理前{}个,清理后{}个,清理了{}个过期记录",
|
||||
sizeBefore, sizeAfter, sizeBefore - sizeAfter);
|
||||
} else {
|
||||
log.debug("机器冷却记录清理完成: 无过期记录需要清理,当前记录数{}", sizeAfter);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("机器冷却记录清理失败: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user