|
@@ -37,14 +37,23 @@ public interface HealthReportDraftMapper extends BaseMapper<HealthReportDraft> {
|
|
|
"WHERE id = #{draftId} AND (next_retry_at IS NULL OR next_retry_at <= #{now})")
|
|
"WHERE id = #{draftId} AND (next_retry_at IS NULL OR next_retry_at <= #{now})")
|
|
|
int claimRetry(@Param("draftId") Long draftId, @Param("now") Date now);
|
|
int claimRetry(@Param("draftId") Long draftId, @Param("now") Date now);
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 原子抢占报告插入槽位:仅当草稿仍在采集中且尚未确认入库时,将 parse_status 改为 'inserting',
|
|
|
|
|
+ * 防止并发的重跑任务在同一份草稿上重复调用 insertReport 创建多份报告。
|
|
|
|
|
+ * 抢到(rows==1)后由调用方执行 insertReport;insertReport 完成会标记 completed。
|
|
|
|
|
+ */
|
|
|
|
|
+ @Update("UPDATE health_report_drafts SET parse_status = 'inserting' " +
|
|
|
|
|
+ "WHERE id = #{draftId} AND parse_status = 'collecting' AND confirmed_report_id IS NULL")
|
|
|
|
|
+ int tryClaimInsertSlot(@Param("draftId") Long draftId);
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 查询待重试草稿:状态 pending + 采集中 + (已到 next_retry_at,或从未有过 next_retry_at 且
|
|
* 查询待重试草稿:状态 pending + 采集中 + (已到 next_retry_at,或从未有过 next_retry_at 且
|
|
|
- * 最近一次解析开始超过10分钟——用于兜底卡死/丢失的采集任务),按 updated_at 升序取前 N 条。
|
|
|
|
|
|
|
+ * 最近一次解析开始超过30分钟——用于兜底卡死/丢失的采集任务),按 updated_at 升序取前 N 条。
|
|
|
*/
|
|
*/
|
|
|
@Select("SELECT * FROM health_report_drafts " +
|
|
@Select("SELECT * FROM health_report_drafts " +
|
|
|
"WHERE status = 'pending' AND parse_status = 'collecting' " +
|
|
"WHERE status = 'pending' AND parse_status = 'collecting' " +
|
|
|
"AND ((next_retry_at IS NOT NULL AND next_retry_at <= #{now}) " +
|
|
"AND ((next_retry_at IS NOT NULL AND next_retry_at <= #{now}) " +
|
|
|
- "OR (next_retry_at IS NULL AND (parse_started_at IS NULL OR parse_started_at < DATE_SUB(#{now}, INTERVAL 10 MINUTE)))) " +
|
|
|
|
|
|
|
+ "OR (next_retry_at IS NULL AND (parse_started_at IS NULL OR parse_started_at < DATE_SUB(#{now}, INTERVAL 30 MINUTE)))) " +
|
|
|
"ORDER BY updated_at ASC LIMIT #{limit}")
|
|
"ORDER BY updated_at ASC LIMIT #{limit}")
|
|
|
List<HealthReportDraft> listPendingRetry(@Param("now") Date now, @Param("limit") int limit);
|
|
List<HealthReportDraft> listPendingRetry(@Param("now") Date now, @Param("limit") int limit);
|
|
|
}
|
|
}
|