Skip to content

Commit 8777e55

Browse files
committed
cleanup
1 parent 8c2a60a commit 8777e55

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

core/src/main/java/org/sterl/spring/persistent_tasks/scheduler/component/TaskExecutorComponent.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,27 @@ public Future<TriggerKey> submit(@Nullable TriggerEntity trigger) {
7070
if (trigger == null) {
7171
return CompletableFuture.completedFuture(null);
7272
}
73-
73+
assertStarted();
7474
try {
75-
Future<TriggerKey> result;
7675
synchronized (runningTasks) {
77-
if (stopped.get() || executor == null) {
78-
throw new IllegalStateException("Executor of " + schedulerName + " is already stopped");
79-
}
80-
result = executor.submit(() -> runTrigger(trigger));
76+
assertStarted();
77+
var result = executor.submit(() -> runTrigger(trigger));
8178
runningTasks.put(trigger, result);
79+
return result;
8280
}
83-
return result;
8481
} catch (Exception e) {
8582
runningTasks.remove(trigger);
8683
throw new RuntimeException("Failed to run " + trigger.getKey(), e);
8784
}
8885

8986
}
9087

88+
private void assertStarted() {
89+
if (stopped.get() || executor == null) {
90+
throw new IllegalStateException("Executor of " + schedulerName + " is already stopped");
91+
}
92+
}
93+
9194
private TriggerKey runTrigger(TriggerEntity trigger) {
9295
try {
9396
triggerService.run(trigger);

0 commit comments

Comments
 (0)