liyong
2 小时以前 7a23c450f3ac85de7dca1b908de273ff636ce218
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package cn.iocoder.yudao.module.im.job.rtc;
 
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
import cn.iocoder.yudao.module.im.framework.config.ImProperties;
import cn.iocoder.yudao.module.im.service.rtc.ImRtcCallService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
 
/**
 * 僵尸通话清理 Job:兜底 LiveKit Webhook 丢失 / 客户端异常关闭等未调 leave 的场景
 *
 * @author 芋道源码
 */
@Component
@Slf4j
public class ImRtcCallCleanupJob implements JobHandler {
 
    @Resource
    private ImRtcCallService rtcCallService;
 
    @Resource
    private ImProperties imProperties;
 
    /**
     * 执行清理
     *
     * @param param 阈值(分钟);为空 / 非法走 {@link ImProperties.Rtc#getCleanupZombieThresholdMinutes()} 默认值
     * @return 清理数量描述
     */
    @Override
    @TenantJob
    public String execute(String param) {
        int thresholdMinutes = resolveThresholdMinutes(param);
        int cleaned = rtcCallService.cleanupZombieCalls(thresholdMinutes);
        log.info("[execute][清理僵尸通话数量 ({}) 个]", cleaned);
        return String.format("清理僵尸通话 %s 个", cleaned);
    }
 
    /**
     * 解析 quartz param 为分钟阈值;非法 / 非正数走配置默认值
     *
     * @param param quartz 调度入参字符串
     * @return 分钟阈值
     */
    private int resolveThresholdMinutes(String param) {
        int defaultMinutes = imProperties.getRtc().getCleanupZombieThresholdMinutes();
        if (StrUtil.isBlank(param) || !NumberUtil.isInteger(param)) {
            return defaultMinutes;
        }
        int minutes = Integer.parseInt(param);
        return minutes > 0 ? minutes : defaultMinutes;
    }
 
}