package xyz.wbsite.frame.schedule;

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.util.Assert;

import java.time.Duration;
import java.util.concurrent.ScheduledFuture;

public abstract class RunDelayRepeatTask extends RunTask {

    public abstract Duration interval();

    @Override
    public ScheduledFuture<?> schedule(ThreadPoolTaskScheduler poolTaskScheduler) {
        Assert.notNull(poolTaskScheduler, "ThreadPoolTaskScheduler must not be null");
        return poolTaskScheduler.scheduleWithFixedDelay(this, interval());
    }
}
