6 changed files with 114 additions and 2 deletions
@ -0,0 +1,15 @@ |
|||
package com.project.classicpaper.config; |
|||
|
|||
import lombok.Data; |
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
@Data |
|||
@Component |
|||
@ConfigurationProperties(prefix = "classicpaper.timeout") |
|||
public class ClassicPaperTimeoutProperties { |
|||
|
|||
private int thresholdMinutes = 120; |
|||
|
|||
private long intervalMs = 300000L; |
|||
} |
|||
@ -0,0 +1,71 @@ |
|||
package com.project.classicpaper.domain.job; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.project.base.config.ScheduledTaskProperties; |
|||
import com.project.classicpaper.config.ClassicPaperTimeoutProperties; |
|||
import com.project.classicpaper.domain.entity.ClassicPaperSetEntity; |
|||
import com.project.classicpaper.domain.enums.ClassicPaperStatusEnum; |
|||
import com.project.classicpaper.domain.service.ClassicPaperSetBaseService; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.scheduling.annotation.Scheduled; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 套题组生成超时检测 |
|||
* 扫描 status=GENERATING 且 create_time 超过阈值的套题组,标记为 FAILED |
|||
* 防止算法侧漏回调导致套题组永久停留在"生成中" |
|||
*/ |
|||
@Service |
|||
@Slf4j |
|||
public class ClassicPaperGenerationTimeoutJob { |
|||
|
|||
@Autowired |
|||
private ClassicPaperSetBaseService classicPaperSetBaseService; |
|||
|
|||
@Autowired |
|||
private ScheduledTaskProperties taskProps; |
|||
|
|||
@Autowired |
|||
private ClassicPaperTimeoutProperties timeoutProps; |
|||
|
|||
@Scheduled(fixedRateString = "${classicpaper.timeout.interval-ms:300000}") |
|||
public void checkSetTimeout() { |
|||
if ("local".equalsIgnoreCase(taskProps.getOwner())) { |
|||
return; |
|||
} |
|||
|
|||
Date cutoff = new Date(System.currentTimeMillis() - timeoutProps.getThresholdMinutes() * 60_000L); |
|||
|
|||
try { |
|||
List<ClassicPaperSetEntity> stale = classicPaperSetBaseService.list( |
|||
new LambdaQueryWrapper<ClassicPaperSetEntity>() |
|||
.eq(ClassicPaperSetEntity::getStatus, ClassicPaperStatusEnum.GENERATING.getValue()) |
|||
.lt(ClassicPaperSetEntity::getCreateTime, cutoff) |
|||
); |
|||
|
|||
if (stale.isEmpty()) { |
|||
return; |
|||
} |
|||
|
|||
for (ClassicPaperSetEntity set : stale) { |
|||
long elapsedMin = (System.currentTimeMillis() - set.getCreateTime().getTime()) / 60_000L; |
|||
boolean updated = classicPaperSetBaseService.lambdaUpdate() |
|||
.eq(ClassicPaperSetEntity::getId, set.getId()) |
|||
.eq(ClassicPaperSetEntity::getStatus, ClassicPaperStatusEnum.GENERATING.getValue()) |
|||
.set(ClassicPaperSetEntity::getStatus, ClassicPaperStatusEnum.FAILED.getValue()) |
|||
.update(); |
|||
|
|||
if (updated) { |
|||
log.warn(">>> [套题超时] setId={}, createTime={}, elapsed={}min, 标记为生成失败", |
|||
set.getId(), set.getCreateTime(), elapsedMin); |
|||
} |
|||
} |
|||
} catch (Exception e) { |
|||
log.error(">>> [套题超时] 扫描异常", e); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue