111
k94314517
2025-07-09 d5984685e7efd46a5e850ade13b22fa727163a47
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
59
60
package com.doumee.config.quartz;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.doumee.biz.system.SystemJobSnippetTriggerBiz;
import com.doumee.biz.system.dto.TriggerJobSnippetDTO;
import com.doumee.core.constants.Constants;
import com.doumee.dao.system.SystemJobSnippetMapper;
import com.doumee.dao.system.model.SystemJobSnippet;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;
 
import java.util.Date;
import java.util.List;
 
/**
 * 分片任务扫描器
 * 该处理器每1秒扫描SYSTEM_JOB_SNIPPET表,执行还未执行的分片任务
 * @author  dm
 * @since 2025/03/31 16:44
 */
@Slf4j
@Component
@DisallowConcurrentExecution
public class SnippetScanner extends QuartzJobBean {
 
    @Autowired
    private SystemJobSnippetTriggerBiz systemJobSnippetTriggerBiz;
 
    @Autowired
    private SystemJobSnippetMapper systemJobSnippetMapper;
 
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        try {
            log.trace("Snippet scanner started.");
            // 1. 查询所有未执行的分片任务
            List<SystemJobSnippet> snippets = systemJobSnippetMapper.selectList(new LambdaQueryWrapper<SystemJobSnippet>()
                    .select(SystemJobSnippet::getId)
                    .eq(SystemJobSnippet::getStatus, Constants.Job.JobStatus.READY.getCode())
                    .orderByAsc(SystemJobSnippet::getCreateTime)
            );
            // 2. 循环执行
            for (SystemJobSnippet snippet : snippets) {
                TriggerJobSnippetDTO dto = new TriggerJobSnippetDTO();
                dto.setId(snippet.getId());
                dto.setTriggerType(Constants.Job.TriggerType.SYSTEM.getCode());
                systemJobSnippetTriggerBiz.trigger(dto);
            }
        } catch (Exception e) {
            throw new JobExecutionException("EVA: trigger snippet throw an exception", e);
        } finally {
            log.trace("Snippet scanner execute completed.");
        }
    }
}