refactor: 修改公共触发监听

This commit is contained in:
fit2-zhao 2023-08-02 18:15:33 +08:00 committed by fit2-zhao
parent c7340cea0a
commit fb01646f23
4 changed files with 6 additions and 21 deletions

View File

@ -1,19 +1,5 @@
package io.metersphere.sdk.listener;
public class Event {
private String message;
private String module;
public record Event(String module, String message) {
public Event(String module, String message) {
this.module = module;
this.message = message;
}
public String getMessage() {
return message;
}
public String getModule() {
return module;
}
}

View File

@ -2,14 +2,12 @@ package io.metersphere.sdk.listener;
public interface EventSource {
/**
* @param listener
* 注册监听
*/
void addListener(EventListener<Event> listener);
/**
* @param module
* @param message
* 触发事件
*/
void fireEvent(String module, String message);
}

View File

@ -24,10 +24,11 @@ public class EventSourceTests {
// 注册所有监听源
LogUtils.info("初始化接口事件源");
APIEventSource apiEventSource = CommonBeanFactory.getBean(APIEventSource.class);
assert apiEventSource != null;
apiEventSource.addListener(new EventListener<Event>() {
@Override
public void onEvent(Event event) {
LogUtils.info("ExecEventListener: " + event.getModule() + "" + event.getMessage());
LogUtils.info("ExecEventListener: " + event.module() + "" + event.message());
}
});
// 触发事件

View File

@ -10,6 +10,6 @@ public class ExecEventListener implements EventListener<Event> {
@Override
public void onEvent(Event event) {
// todo: 测试计划事件处理逻辑
LogUtils.info("ExecEventListener: " + event.getModule() + "" + event.getMessage());
LogUtils.info("ExecEventListener: " + event.module() + "" + event.message());
}
}