|
@@ -209,6 +209,9 @@ public class AppTaskService {
|
|
|
findFile(t, template, dirPath, fileList, processQueryKeys);
|
|
|
}
|
|
|
}
|
|
|
+ // 执行完删除重试任务
|
|
|
+ iRetryAppTaskService.removeById(t.getTaskId());
|
|
|
+ RETRY_TASKS.remove(t.getTaskId());
|
|
|
log.info("结束应用任务: {}", t);
|
|
|
String content = t.getAppName() + " " + t.getTaskName() + " 执行成功" + " : "
|
|
|
+ gson.toJson(processQueryKeys);
|
|
@@ -224,24 +227,24 @@ public class AppTaskService {
|
|
|
appTaskLogPo.setDetail(e.toString());
|
|
|
log.error("线程中断: {}, {}", t, e, e);
|
|
|
Thread.currentThread().interrupt();
|
|
|
- retry(t);
|
|
|
alert(t, "任务意外中断");
|
|
|
+ retry(t);
|
|
|
} catch (TimeoutException e) {
|
|
|
appTaskLogPo.setStatus(0);
|
|
|
appTaskLogPo.setDetail(e.toString());
|
|
|
log.error("应用任务执行超时: {}, {}", t, e, e);
|
|
|
- retry(t);
|
|
|
alert(t, "任务执行超时");
|
|
|
+ retry(t);
|
|
|
} catch (Exception e) {
|
|
|
appTaskLogPo.setStatus(0);
|
|
|
appTaskLogPo.setDetail(e.toString());
|
|
|
log.error("应用任务执行失败: {}, {}", t, e, e);
|
|
|
- retry(t);
|
|
|
Throwable rootCause = e;
|
|
|
while (rootCause.getCause() != null && rootCause.getCause() != rootCause) {
|
|
|
rootCause = rootCause.getCause();
|
|
|
}
|
|
|
alert(t, rootCause.getMessage());
|
|
|
+ retry(t);
|
|
|
} finally {
|
|
|
// 记录日志
|
|
|
appTaskLogPo.setFiles(gson.toJson(fileList));
|
|
@@ -289,44 +292,48 @@ public class AppTaskService {
|
|
|
* @param content 内容
|
|
|
*/
|
|
|
public void sendMessage(AppTaskBo t, String content) {
|
|
|
- String robotCode = t.getRobotCode();
|
|
|
- String robotSecret = t.getRobotSecret();
|
|
|
- String openConversationId = t.getOpenConversationId();
|
|
|
- String phones = t.getPhones();
|
|
|
- String userIds = t.getUserIds();
|
|
|
- if (TaskAlertTypeEnum.DEFAULT.name().equals(t.getAlertType())) {
|
|
|
- AlertConfigPo alertConfigPo = iAlertConfigService.getById(1);
|
|
|
- if (alertConfigPo == null) {
|
|
|
+ try {
|
|
|
+ String robotCode = t.getRobotCode();
|
|
|
+ String robotSecret = t.getRobotSecret();
|
|
|
+ String openConversationId = t.getOpenConversationId();
|
|
|
+ String phones = t.getPhones();
|
|
|
+ String userIds = t.getUserIds();
|
|
|
+ if (TaskAlertTypeEnum.DEFAULT.name().equals(t.getAlertType())) {
|
|
|
+ AlertConfigPo alertConfigPo = iAlertConfigService.getById(1);
|
|
|
+ if (alertConfigPo == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ robotCode = alertConfigPo.getRobotCode();
|
|
|
+ robotSecret = alertConfigPo.getRobotSecret();
|
|
|
+ openConversationId = alertConfigPo.getOpenConversationId();
|
|
|
+ phones = alertConfigPo.getPhones();
|
|
|
+ userIds = alertConfigPo.getUserIds();
|
|
|
+ } else if (TaskAlertTypeEnum.CUSTOM.name().equals(t.getAlertType())) {
|
|
|
+ robotCode = t.getAlertRobotCode();
|
|
|
+ robotSecret = t.getAlertRobotSecret();
|
|
|
+ openConversationId = t.getAlertOpenConversationId();
|
|
|
+ phones = t.getAlertPhones();
|
|
|
+ userIds = t.getAlertUserIds();
|
|
|
+ }
|
|
|
+ if (!StringUtils.hasText(robotCode)
|
|
|
+ || !StringUtils.hasText(robotSecret)
|
|
|
+ || (!StringUtils.hasText(openConversationId)
|
|
|
+ && !StringUtils.hasText(phones)
|
|
|
+ && !StringUtils.hasText(userIds))) {
|
|
|
return;
|
|
|
}
|
|
|
- robotCode = alertConfigPo.getRobotCode();
|
|
|
- robotSecret = alertConfigPo.getRobotSecret();
|
|
|
- openConversationId = alertConfigPo.getOpenConversationId();
|
|
|
- phones = alertConfigPo.getPhones();
|
|
|
- userIds = alertConfigPo.getUserIds();
|
|
|
- } else if (TaskAlertTypeEnum.CUSTOM.name().equals(t.getAlertType())) {
|
|
|
- robotCode = t.getAlertRobotCode();
|
|
|
- robotSecret = t.getAlertRobotSecret();
|
|
|
- openConversationId = t.getAlertOpenConversationId();
|
|
|
- phones = t.getAlertPhones();
|
|
|
- userIds = t.getAlertUserIds();
|
|
|
- }
|
|
|
- if (!StringUtils.hasText(robotCode)
|
|
|
- || !StringUtils.hasText(robotSecret)
|
|
|
- || (!StringUtils.hasText(openConversationId)
|
|
|
- && !StringUtils.hasText(phones)
|
|
|
- && !StringUtils.hasText(userIds))) {
|
|
|
- return;
|
|
|
- }
|
|
|
- String accessToken = openService.getAccessToken(robotCode, robotSecret);
|
|
|
- if (StringUtils.hasText(openConversationId)) {
|
|
|
- DingTalkApiUtil.groupSendSampleText(content, accessToken, openConversationId,
|
|
|
- robotCode);
|
|
|
- }
|
|
|
- if (StringUtils.hasText(phones) || StringUtils.hasText(userIds)) {
|
|
|
- List<String> userIdList = getUserIdList(phones, userIds,
|
|
|
- accessToken);
|
|
|
- DingTalkApiUtil.batchSendOtoSampleText(content, accessToken, robotCode, userIdList);
|
|
|
+ String accessToken = openService.getAccessToken(robotCode, robotSecret);
|
|
|
+ if (StringUtils.hasText(openConversationId)) {
|
|
|
+ DingTalkApiUtil.groupSendSampleText(content, accessToken, openConversationId,
|
|
|
+ robotCode);
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(phones) || StringUtils.hasText(userIds)) {
|
|
|
+ List<String> userIdList = getUserIdList(phones, userIds,
|
|
|
+ accessToken);
|
|
|
+ DingTalkApiUtil.batchSendOtoSampleText(content, accessToken, robotCode, userIdList);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送通知失败: {}", e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|