|
@@ -1,13 +1,12 @@
|
|
|
package cn.reghao.devops.manager.notification;
|
|
package cn.reghao.devops.manager.notification;
|
|
|
|
|
|
|
|
-import cn.reghao.devops.manager.config.WebhookProperties;
|
|
|
|
|
import cn.reghao.devops.manager.notification.notifier.Notify;
|
|
import cn.reghao.devops.manager.notification.notifier.Notify;
|
|
|
import cn.reghao.devops.manager.notification.notifier.ding.DingMsg;
|
|
import cn.reghao.devops.manager.notification.notifier.ding.DingMsg;
|
|
|
|
|
+import cn.reghao.devops.manager.notification.notifier.ding.DingNotify;
|
|
|
|
|
+import cn.reghao.devops.manager.notification.notifier.email.EmailMsg;
|
|
|
|
|
+import cn.reghao.devops.manager.notification.notifier.email.EmailNotify;
|
|
|
import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
|
|
import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.BeansException;
|
|
|
|
|
-import org.springframework.beans.factory.BeanFactory;
|
|
|
|
|
-import org.springframework.beans.factory.BeanFactoryAware;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.ExecutorService;
|
|
@@ -20,34 +19,31 @@ import java.util.concurrent.ExecutorService;
|
|
|
*/
|
|
*/
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
-public class NotifyService implements BeanFactoryAware {
|
|
|
|
|
- private BeanFactory beanFactory;
|
|
|
|
|
|
|
+public class NotifyService {
|
|
|
private final ExecutorService threadPool = ThreadPoolWrapper.threadPool("notify-service");
|
|
private final ExecutorService threadPool = ThreadPoolWrapper.threadPool("notify-service");
|
|
|
- private final WebhookProperties webhookProperties;
|
|
|
|
|
- private final Notify notify;
|
|
|
|
|
|
|
+ private final NotifyReceiver notifyReceiver;
|
|
|
|
|
+ private final DingNotify dingNotify;
|
|
|
|
|
+ private final EmailNotify emailNotify;
|
|
|
|
|
|
|
|
- public NotifyService(WebhookProperties webhookProperties, Notify notify) {
|
|
|
|
|
- this.webhookProperties = webhookProperties;
|
|
|
|
|
- this.notify = notify;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
|
|
|
|
- this.beanFactory = beanFactory;
|
|
|
|
|
|
|
+ public NotifyService(NotifyReceiver notifyReceiver, DingNotify dingNotify, EmailNotify emailNotify) {
|
|
|
|
|
+ this.notifyReceiver = notifyReceiver;
|
|
|
|
|
+ this.dingNotify = dingNotify;
|
|
|
|
|
+ this.emailNotify = emailNotify;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public <T> void notify(T msg) {
|
|
public <T> void notify(T msg) {
|
|
|
- /*Object object = beanFactory.getBean("webhookProperties");
|
|
|
|
|
- if (object instanceof WebhookProperties) {
|
|
|
|
|
- WebhookProperties webhookProperties = (WebhookProperties) object;
|
|
|
|
|
- DingMsg dingMsg = (DingMsg) msg;
|
|
|
|
|
- String receiver = webhookProperties.getUrl();
|
|
|
|
|
- threadPool.execute(new NotifyTask<DingMsg>(notify, receiver, dingMsg));
|
|
|
|
|
- }*/
|
|
|
|
|
|
|
+ String receiver = notifyReceiver.getUrl();
|
|
|
|
|
+ notify(receiver, msg);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- DingMsg dingMsg = (DingMsg) msg;
|
|
|
|
|
- String receiver = webhookProperties.getUrl();
|
|
|
|
|
- threadPool.execute(new NotifyTask<DingMsg>(notify, receiver, dingMsg));
|
|
|
|
|
|
|
+ public <T> void notify(String receiver, T msg) {
|
|
|
|
|
+ if (msg instanceof DingMsg) {
|
|
|
|
|
+ DingMsg dingMsg = (DingMsg) msg;
|
|
|
|
|
+ threadPool.execute(new NotifyTask<>(dingNotify, receiver, dingMsg));
|
|
|
|
|
+ } else if (msg instanceof EmailMsg) {
|
|
|
|
|
+ EmailMsg emailMsg = (EmailMsg) msg;
|
|
|
|
|
+ threadPool.execute(new NotifyTask<>(emailNotify, receiver, emailMsg));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
/**
|
|
/**
|
|
|
* @param
|
|
* @param
|