mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
[dev] formate alarm info, which is more friendly to developer
This commit is contained in:
parent
5c37d6e61e
commit
986aa712a0
@ -0,0 +1,34 @@
|
||||
package com.github.kfcfans.powerjob.server.service.alarm;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.kfcfans.powerjob.common.OmsSerializable;
|
||||
import com.github.kfcfans.powerjob.common.utils.CommonUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* 报警内容
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2020/8/1
|
||||
*/
|
||||
public interface AlarmContent extends OmsSerializable {
|
||||
|
||||
default String fetchContent() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
JSONObject content = JSONObject.parseObject(JSONObject.toJSONString(this));
|
||||
content.forEach((key, originWord) -> {
|
||||
sb.append(key).append(": ");
|
||||
String word = String.valueOf(originWord);
|
||||
if (StringUtils.endsWithIgnoreCase(key, "time") || StringUtils.endsWithIgnoreCase(key, "date")) {
|
||||
try {
|
||||
if (originWord instanceof Long) {
|
||||
word = CommonUtils.formatTime((Long) originWord);
|
||||
}
|
||||
}catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
sb.append(word).append("\n\r");
|
||||
});
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package com.github.kfcfans.powerjob.server.service.alarm;
|
||||
|
||||
import com.github.kfcfans.powerjob.common.utils.JsonUtils;
|
||||
import com.github.kfcfans.powerjob.server.persistence.core.model.UserInfoDO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -38,13 +37,13 @@ public class DefaultMailAlarmService implements Alarmable {
|
||||
|
||||
@Override
|
||||
public void onJobInstanceFailed(JobInstanceAlarmContent content, List<UserInfoDO> targetUserList) {
|
||||
String msg = String.format(JOB_INSTANCE_FAILED_CONTENT_PATTERN, JsonUtils.toJSONString(content));
|
||||
String msg = String.format(JOB_INSTANCE_FAILED_CONTENT_PATTERN, content.fetchContent());
|
||||
sendMail(msg, targetUserList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorkflowInstanceFailed(WorkflowInstanceAlarmContent content, List<UserInfoDO> targetUserList) {
|
||||
String msg = String.format(WF_INSTANCE_FAILED_CONTENT_PATTERN, JsonUtils.toJSONString(content));
|
||||
String msg = String.format(WF_INSTANCE_FAILED_CONTENT_PATTERN, content.fetchContent());
|
||||
sendMail(msg, targetUserList);
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import lombok.Data;
|
||||
* @since 2020/4/30
|
||||
*/
|
||||
@Data
|
||||
public class JobInstanceAlarmContent {
|
||||
public class JobInstanceAlarmContent implements AlarmContent {
|
||||
// 应用ID
|
||||
private long appId;
|
||||
// 任务ID
|
||||
|
@ -10,7 +10,7 @@ import lombok.Data;
|
||||
* @since 2020/6/12
|
||||
*/
|
||||
@Data
|
||||
public class WorkflowInstanceAlarmContent {
|
||||
public class WorkflowInstanceAlarmContent implements AlarmContent {
|
||||
|
||||
private String workflowName;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user