fix(ops): 启动时恢复工单队列缓存
- 新增 OrderQueueInitializer\n- 服务启动时调用 QueueSyncService.forceSyncAll()\n- 在 Redis 队列数据丢失或过期后,自动用 MySQL 数据回填 Sorted Set
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package com.viewsh.module.ops.framework.job.queue;
|
||||
|
||||
import com.viewsh.framework.tenant.core.util.TenantUtils;
|
||||
import com.viewsh.module.ops.service.queue.QueueSyncService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 工单队列 Redis 启动恢复器
|
||||
* <p>
|
||||
* 职责:服务启动时,全量同步 MySQL 队列数据到 Redis,
|
||||
* 确保 Redis Sorted Set 与 MySQL 一致。
|
||||
* <p>
|
||||
* 解决场景:
|
||||
* - 服务重启后 Redis 队列数据丢失或过期
|
||||
* - 异步写入 Redis 失败导致的数据不一致
|
||||
*
|
||||
* @author AI
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class OrderQueueInitializer implements ApplicationRunner {
|
||||
|
||||
@Resource
|
||||
private QueueSyncService queueSyncService;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
log.info("[初始化] 开始全量同步工单队列到 Redis...");
|
||||
|
||||
try {
|
||||
TenantUtils.executeIgnore(() -> {
|
||||
int count = queueSyncService.forceSyncAll();
|
||||
log.info("[初始化] 工单队列全量同步完成:同步 {} 条记录", count);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error("[初始化] 工单队列全量同步失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user