feat(sj_1.0.0):

1、Webhook告警、工作流回调请求密钥常量
This commit is contained in:
wodeyangzipingpingwuqi 2024-05-07 16:41:52 +08:00
parent e4fe69d870
commit 30221e8339
3 changed files with 9 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.aizuda.snailjob.common.core.alarm.AlarmContext;
import com.aizuda.snailjob.common.core.alarm.attribute.WebhookAttribute;
import com.aizuda.snailjob.common.core.constant.SystemConstants;
import com.aizuda.snailjob.common.core.enums.AlarmTypeEnum;
import com.aizuda.snailjob.common.core.enums.ContentTypeEnum;
import com.aizuda.snailjob.common.core.util.JsonUtil;
@ -39,7 +40,7 @@ public class WebhookAlarm extends AbstractAlarm<AlarmContext> {
HttpRequest post = HttpUtil.createPost(webhookAttribute.getWebhookUrl());
HttpRequest request = post.body(JsonUtil.toJsonString(webhookMessage), ContentTypeEnum.valueOf(webhookAttribute.getContentType()).getMediaType().toString())
.header("secret", webhookAttribute.getSecret());
.header(SystemConstants.SECRET, webhookAttribute.getSecret());
HttpResponse execute = request.execute();
if (execute.isOk()) {
return true;

View File

@ -146,4 +146,9 @@ public interface SystemConstants {
* 日志类型字段
*/
String JSON_FILED_LOG_TYPE = "logType" ;
/**
* Webhook告警工作流回调请求密钥
*/
String SECRET = "secret" ;
}

View File

@ -44,7 +44,6 @@ import java.util.concurrent.TimeUnit;
@RequiredArgsConstructor
public class CallbackWorkflowExecutor extends AbstractWorkflowExecutor {
private static final String SECRET = "secret";
private static final String CALLBACK_TIMEOUT = "10";
private final RestTemplate restTemplate;
private final JobTaskMapper jobTaskMapper;
@ -87,7 +86,7 @@ public class CallbackWorkflowExecutor extends AbstractWorkflowExecutor {
String result = null;
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.set(SECRET, decisionConfig.getSecret());
requestHeaders.set(SystemConstants.SECRET, decisionConfig.getSecret());
requestHeaders.setContentType(ContentTypeEnum.valueOf(decisionConfig.getContentType()).getMediaType());
// 设置回调超时时间
requestHeaders.set(RequestInterceptor.TIMEOUT_TIME, CALLBACK_TIMEOUT);
@ -101,7 +100,7 @@ public class CallbackWorkflowExecutor extends AbstractWorkflowExecutor {
try {
Map<String, String> uriVariables = new HashMap<>();
uriVariables.put(SECRET, decisionConfig.getSecret());
uriVariables.put(SystemConstants.SECRET, decisionConfig.getSecret());
ResponseEntity<String> response = buildRetryer(decisionConfig).call(
() -> restTemplate.exchange(decisionConfig.getWebhook(), HttpMethod.POST,