WebhookRetryTask.java
1.43 KB
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
package com.diligrp.rider.task;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.diligrp.rider.entity.WebhookLog;
import com.diligrp.rider.mapper.WebhookLogMapper;
import com.diligrp.rider.service.WebhookService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor
public class WebhookRetryTask {
private final WebhookLogMapper webhookLogMapper;
private final WebhookService webhookService;
@XxlJob("webhookRetryHandler")
public void retryFailedWebhooks() {
try {
List<WebhookLog> logs = webhookLogMapper.selectList(new LambdaQueryWrapper<WebhookLog>()
.eq(WebhookLog::getStatus, 0)
.lt(WebhookLog::getRetryCount, 5)
.orderByAsc(WebhookLog::getCreateTime)
.last("LIMIT 20"));
for (WebhookLog webhookLog : logs) {
try {
webhookService.retry(webhookLog.getId());
} catch (Exception e) {
log.warn("Webhook 自动重试失败 logId={}", webhookLog.getId(), e);
}
}
} catch (Exception e) {
log.error("Webhook 重试任务异常", e);
throw new RuntimeException(e);
}
}
}