Skip to content

Commit 24a1076

Browse files
committed
Refactor MetricsService to use getSyncExecutor for async snapshot collection
1 parent 83d1778 commit 24a1076

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

common/src/main/java/it/renvins/serverpulse/common/MetricsService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void collectAndSendMetrics() {
5757
ServerPulseProvider.get().getDatabaseService().startRetryTaskIfNeeded();
5858
return;
5959
}
60-
CompletableFuture.supplyAsync(this::collectSnapshot, scheduler::runSync)
60+
CompletableFuture.supplyAsync(this::collectSnapshot, scheduler.getSyncExecutor())
6161
.thenApplyAsync(snapshot -> {
6262
if (snapshot == null) {
6363
logger.warning("Snapshot is null. Skipping metrics send.");

common/src/main/java/it/renvins/serverpulse/common/scheduler/TaskScheduler.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package it.renvins.serverpulse.common.scheduler;
22

3+
import java.util.concurrent.Executor;
4+
35
public interface TaskScheduler {
46

57
/**
@@ -54,4 +56,12 @@ default Task runTaskLater(Runnable task, long delayTicks) {
5456
* @return A Task object representing the task
5557
*/
5658
Task runTaskLaterAsync(Runnable task, long delayTicks);
59+
60+
default Executor getSyncExecutor() {
61+
try {
62+
return this::runSync;
63+
} catch (UnsupportedOperationException e) {
64+
return this::runAsync;
65+
}
66+
}
5767
}

0 commit comments

Comments
 (0)