Skip to content

Commit ec518d8

Browse files
aq-ikhwa-techludomikula
authored andcommitted
Publish server log event for ee plugin to consume
1 parent 1b820ca commit ec518d8

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

server/api-service/lowcoder-infra/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@
127127
<groupId>org.springframework.boot</groupId>
128128
<artifactId>spring-boot-starter-webflux</artifactId>
129129
</dependency>
130+
<dependency>
131+
<groupId>org.lowcoder.plugin</groupId>
132+
<artifactId>lowcoder-plugin-api</artifactId>
133+
<version>2.1.0</version>
134+
<scope>compile</scope>
135+
</dependency>
130136

131137
</dependencies>
132138

server/api-service/lowcoder-infra/src/main/java/org/lowcoder/infra/serverlog/ServerLogService.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
import org.apache.commons.collections4.CollectionUtils;
1010
import org.lowcoder.infra.perf.PerfHelper;
11+
import org.lowcoder.plugin.events.ServerLogEvent;
1112
import org.springframework.beans.factory.annotation.Autowired;
13+
import org.springframework.context.ApplicationEventPublisher;
1214
import org.springframework.scheduling.annotation.Scheduled;
1315
import org.springframework.stereotype.Service;
1416

@@ -23,6 +25,9 @@ public class ServerLogService {
2325
@Autowired
2426
private PerfHelper perfHelper;
2527

28+
@Autowired
29+
private ApplicationEventPublisher applicationEventPublisher;
30+
2631
private volatile Queue<ServerLog> serverLogs = new ConcurrentLinkedQueue<>();
2732

2833
public void record(ServerLog serverLog) {
@@ -39,7 +44,15 @@ private void scheduledInsert() {
3944
serverLogRepository.saveAll(tmp)
4045
.collectList()
4146
.subscribe(result -> {
47+
int count = result.size();
4248
perfHelper.count(SERVER_LOG_BATCH_INSERT, Tags.of("size", String.valueOf(result.size())));
49+
publishServerLogEvent(count);
4350
});
4451
}
52+
53+
private void publishServerLogEvent(int count) {
54+
ServerLogEvent event = new ServerLogEvent();
55+
event.setApiCallsCount(count);
56+
applicationEventPublisher.publishEvent(event);
57+
}
4558
}

0 commit comments

Comments
 (0)