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;

/**
 * 重复任务，任务A开始后经过指定时间后执行B，无论A是否结束
 *
 * @author wangbing
 * @version 0.0.1
 * @since 2020-01-01
 */
public abstract class RunFixRepeatTask extends RunTask {

    public abstract Duration interval();

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