Fix custom scheduler support for @Scheduled methods
This commit fixes a regression introduced by gh-24560, when adding execution metadata support for scheduled tasks. The `OutcomeTrackingRunnable` would delegate to the actual runnable but could also hide whether it implements the `SchedulingAwareRunnable` contract. This commit ensures that `OutcomeTrackingRunnable` always implements that contract and delegates to the runnable if possible, or return default values otherwise. Fixes gh-34058
This commit is contained in:
@@ -18,6 +18,8 @@ package org.springframework.scheduling.config;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.scheduling.SchedulingAwareRunnable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -68,7 +70,7 @@ public class Task {
|
||||
}
|
||||
|
||||
|
||||
private class OutcomeTrackingRunnable implements Runnable {
|
||||
private class OutcomeTrackingRunnable implements SchedulingAwareRunnable {
|
||||
|
||||
private final Runnable runnable;
|
||||
|
||||
@@ -89,6 +91,23 @@ public class Task {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLongLived() {
|
||||
if (this.runnable instanceof SchedulingAwareRunnable sar) {
|
||||
return sar.isLongLived();
|
||||
}
|
||||
return SchedulingAwareRunnable.super.isLongLived();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getQualifier() {
|
||||
if (this.runnable instanceof SchedulingAwareRunnable sar) {
|
||||
return sar.getQualifier();
|
||||
}
|
||||
return SchedulingAwareRunnable.super.getQualifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.runnable.toString();
|
||||
|
||||
Reference in New Issue
Block a user