Package cn.boboweike.carrot.scheduling
Class TaskScheduler
- java.lang.Object
-
- cn.boboweike.carrot.scheduling.AbstractTaskScheduler
-
- cn.boboweike.carrot.scheduling.TaskScheduler
-
public class TaskScheduler extends AbstractTaskScheduler
Provides methods for creating fire-and-forget, delayed and recurring tasks as well as to delete existing background tasks.This
TaskSchedulerallows to schedule tasks by means of a Java 8 lambda which is analyzed.- Author:
- boboweike
-
-
Constructor Summary
Constructors Constructor Description TaskScheduler(PartitionedStorageProvider storageProvider)Creates a new TaskScheduler using the provided storageProviderTaskScheduler(PartitionedStorageProvider storageProvider, TaskDetailsGenerator taskDetailsGenerator, List<TaskFilter> taskFilters)TaskScheduler(PartitionedStorageProvider storageProvider, List<TaskFilter> taskFilters)Creates a new TaskScheduler using the provided storageProvider and the list of TaskFilters that will be used for every background task
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <S> TaskIdenqueue(IocTaskLambda<S> iocTask)Creates a new fire-and-forget task based on a given lambda.TaskIdenqueue(TaskLambda task)Creates a new fire-and-forget task based on a given lambda.<S,T>
voidenqueue(Stream<T> input, IocTaskLambdaFromStream<S,T> iocTaskFromStream)Creates new fire-and-forget tasks for each item in the input stream using the lambda passed astaskFromStream.<T> voidenqueue(Stream<T> input, TaskLambdaFromStream<T> taskFromStream)Creates new fire-and-forget tasks for each item in the input stream using the lambda passed astaskFromStream.<S> TaskIdenqueue(UUID id, IocTaskLambda<S> iocTask)Creates a new fire-and-forget task based on a given lambda.TaskIdenqueue(UUID id, TaskLambda task)Creates a new fire-and-forget task based on the given lambda.<S> TaskIdschedule(Instant instant, IocTaskLambda<S> iocTask)Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.TaskIdschedule(Instant instant, TaskLambda task)Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.<S> TaskIdschedule(LocalDateTime localDateTime, IocTaskLambda<S> iocTask)Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.TaskIdschedule(LocalDateTime localDateTime, TaskLambda task)Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.<S> TaskIdschedule(OffsetDateTime offsetDateTime, IocTaskLambda<S> iocTask)Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.TaskIdschedule(OffsetDateTime offsetDateTime, TaskLambda task)Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.<S> TaskIdschedule(ZonedDateTime zonedDateTime, IocTaskLambda<S> iocTask)Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.TaskIdschedule(ZonedDateTime zonedDateTime, TaskLambda task)Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.<S> TaskIdschedule(UUID id, Instant instant, IocTaskLambda<S> iocTask)Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.TaskIdschedule(UUID id, Instant instant, TaskLambda task)Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.<S> TaskIdschedule(UUID id, LocalDateTime localDateTime, IocTaskLambda<S> iocTask)Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.TaskIdschedule(UUID id, LocalDateTime localDateTime, TaskLambda task)Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.<S> TaskIdschedule(UUID id, OffsetDateTime offsetDateTime, IocTaskLambda<S> iocTask)Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.TaskIdschedule(UUID id, OffsetDateTime offsetDateTime, TaskLambda task)Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.<S> TaskIdschedule(UUID id, ZonedDateTime zonedDateTime, IocTaskLambda<S> iocTask)Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.TaskIdschedule(UUID id, ZonedDateTime zonedDateTime, TaskLambda task)Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.<S> StringscheduleRecurrently(String cron, IocTaskLambda<S> iocTask)Creates a new recurring task based on the given cron expression and the given lambda.StringscheduleRecurrently(String cron, TaskLambda task)Creates a new recurring task based on the given lambda and the given cron expression.<S> StringscheduleRecurrently(String id, String cron, IocTaskLambda<S> iocTask)Creates a new or alters the existing recurring task based on the given id, cron expression and lambda.StringscheduleRecurrently(String id, String cron, TaskLambda task)Creates a new or alters the existing recurring task based on the given id, cron expression and lambda.<S> StringscheduleRecurrently(String id, String cron, ZoneId zoneId, IocTaskLambda<S> iocTask)Creates a new or alters the existing recurring task based on the given id, cron expression,ZoneIdand lambda.StringscheduleRecurrently(String id, String cron, ZoneId zoneId, TaskLambda task)Creates a new or alters the existing recurring task based on the given id, cron expression,ZoneIdand lambda.<S> StringscheduleRecurrently(String id, Duration duration, IocTaskLambda<S> iocTask)Creates a new or alters the existing recurring task based on the given id, duration and lambda.StringscheduleRecurrently(String id, Duration duration, TaskLambda task)Creates a new or alters the existing recurring task based on the given id, duration and lambda.<S> StringscheduleRecurrently(Duration duration, IocTaskLambda<S> iocTask)Creates a new recurring task based on the given duration and the given lambda.StringscheduleRecurrently(Duration duration, TaskLambda task)Creates a new recurring task based on the given duration and the given lambda.
-
-
-
Constructor Detail
-
TaskScheduler
public TaskScheduler(PartitionedStorageProvider storageProvider)
Creates a new TaskScheduler using the provided storageProvider- Parameters:
storageProvider- the storageProvider to use
-
TaskScheduler
public TaskScheduler(PartitionedStorageProvider storageProvider, List<TaskFilter> taskFilters)
Creates a new TaskScheduler using the provided storageProvider and the list of TaskFilters that will be used for every background task- Parameters:
storageProvider- the storageProvider to usetaskFilters- list of taskFilters that will be used for every task
-
TaskScheduler
public TaskScheduler(PartitionedStorageProvider storageProvider, TaskDetailsGenerator taskDetailsGenerator, List<TaskFilter> taskFilters)
-
-
Method Detail
-
enqueue
public TaskId enqueue(TaskLambda task)
Creates a new fire-and-forget task based on a given lambda.An example:
MyService service = new MyService(); taskScheduler.enqueue(() -> service.doWork());- Parameters:
task- the lambda which defines the fire-and-forget task- Returns:
- the id of the task
-
enqueue
public TaskId enqueue(UUID id, TaskLambda task)
Creates a new fire-and-forget task based on the given lambda. If a task with that id already exists, Carrot will not save it again.An example:
MyService service = new MyService(); taskScheduler.enqueue(id, () -> service.doWork());- Parameters:
id- the uuid with which to save the tasktask- the lambda which defines the fire-and-forget task- Returns:
- the id of the task
-
enqueue
public <T> void enqueue(Stream<T> input, TaskLambdaFromStream<T> taskFromStream)
Creates new fire-and-forget tasks for each item in the input stream using the lambda passed astaskFromStream.An example:
MyService service = new MyService(); Stream<UUID> workStream = getWorkStream(); taskScheduler.enqueue(workStream, (uuid) -> service.doWork(uuid));- Type Parameters:
T- generic type for TaskLambdaFromStream- Parameters:
input- the stream of items for which to create fire-and-forget taskstaskFromStream- the lambda which defines the fire-and-forget task to create for each item in theinput
-
enqueue
public <S> TaskId enqueue(IocTaskLambda<S> iocTask)
Creates a new fire-and-forget task based on a given lambda. The IoC container will be used to resolveMyService.An example:
taskScheduler.<MyService>enqueue(x -> x.doWork());- Type Parameters:
S- generic type for IocTaskLambda- Parameters:
iocTask- the lambda which defines the fire-and-forget task- Returns:
- the id of the task
-
enqueue
public <S> TaskId enqueue(UUID id, IocTaskLambda<S> iocTask)
Creates a new fire-and-forget task based on a given lambda. The IoC container will be used to resolveMyService. If a task with that id already exists, Carrot will not save it again.An example:
taskScheduler.<MyService>enqueue(id, x -> x.doWork());- Type Parameters:
S- generic type for IocTaskLambda- Parameters:
id- the uuid with which to save the taskiocTask- the lambda which defines the fire-and-forget task- Returns:
- the id of the task
-
enqueue
public <S,T> void enqueue(Stream<T> input, IocTaskLambdaFromStream<S,T> iocTaskFromStream)
Creates new fire-and-forget tasks for each item in the input stream using the lambda passed astaskFromStream. The IoC container will be used to resolveMyService.An example:
Stream<UUID> workStream = getWorkStream(); taskScheduler.<MyService, UUID>enqueue(workStream, (x, uuid) -> x.doWork(uuid));- Type Parameters:
T- generic type for IocTaskLambdaFromStreamS- generic type for IocTaskLambdaFromStream- Parameters:
input- the stream of items for which to create fire-and-forget tasksiocTaskFromStream- the lambda which defines the fire-and-forget task to create for each item in theinput
-
schedule
public TaskId schedule(ZonedDateTime zonedDateTime, TaskLambda task)
Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.An example:
MyService service = new MyService(); taskScheduler.schedule(ZonedDateTime.now().plusHours(5), () -> service.doWork());- Parameters:
zonedDateTime- the moment in time at which the task will be enqueued.task- the lambda which defines the fire-and-forget task- Returns:
- the id of the Task
-
schedule
public TaskId schedule(UUID id, ZonedDateTime zonedDateTime, TaskLambda task)
Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time. If a task with that id already exists, Carrot will not save it again.An example:
MyService service = new MyService(); taskScheduler.schedule(id, ZonedDateTime.now().plusHours(5), () -> service.doWork());- Parameters:
id- the uuid with which to save the taskzonedDateTime- the moment in time at which the task will be enqueued.task- the lambda which defines the fire-and-forget task- Returns:
- the id of the Task
-
schedule
public <S> TaskId schedule(ZonedDateTime zonedDateTime, IocTaskLambda<S> iocTask)
Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time. The IoC container will be used to resolveMyService.An example:
taskScheduler.<MyService>schedule(ZonedDateTime.now().plusHours(5), x -> x.doWork());- Type Parameters:
S- generic type for IocTaskLambda- Parameters:
zonedDateTime- the moment in time at which the task will be enqueued.iocTask- the lambda which defines the fire-and-forget task- Returns:
- the id of the Task
-
schedule
public <S> TaskId schedule(UUID id, ZonedDateTime zonedDateTime, IocTaskLambda<S> iocTask)
Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time. The IoC container will be used to resolveMyService. If a task with that id already exists, Carrot will not save it again.An example:
taskScheduler.<MyService>schedule(id, ZonedDateTime.now().plusHours(5), x -> x.doWork());- Type Parameters:
S- generic type for IocTaskLambda- Parameters:
id- the uuid with which to save the taskzonedDateTime- the moment in time at which the task will be enqueued.iocTask- the lambda which defines the fire-and-forget task- Returns:
- the id of the Task
-
schedule
public TaskId schedule(OffsetDateTime offsetDateTime, TaskLambda task)
Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.An example:
MyService service = new MyService(); taskScheduler.schedule(OffsetDateTime.now().plusHours(5), () -> service.doWork());- Parameters:
offsetDateTime- The moment in time at which the task will be enqueued.task- the lambda which defines the fire-and-forget task- Returns:
- the id of the Task
-
schedule
public TaskId schedule(UUID id, OffsetDateTime offsetDateTime, TaskLambda task)
Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time. If a task with that id already exists, Carrot will not save it again.An example:
MyService service = new MyService(); taskScheduler.schedule(id, OffsetDateTime.now().plusHours(5), () -> service.doWork());- Parameters:
id- the uuid with which to save the taskoffsetDateTime- The moment in time at which the task will be enqueued.task- the lambda which defines the fire-and-forget task- Returns:
- the id of the Task
-
schedule
public <S> TaskId schedule(OffsetDateTime offsetDateTime, IocTaskLambda<S> iocTask)
Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time. The IoC container will be used to resolveMyService.An example:
taskScheduler.<MyService>schedule(OffsetDateTime.now().plusHours(5), x -> x.doWork());- Type Parameters:
S- generic type for IocTaskLambda- Parameters:
offsetDateTime- The moment in time at which the task will be enqueued.iocTask- the lambda which defines the fire-and-forget task- Returns:
- the id of the Task
-
schedule
public <S> TaskId schedule(UUID id, OffsetDateTime offsetDateTime, IocTaskLambda<S> iocTask)
Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time. The IoC container will be used to resolveMyService. If a task with that id already exists, Carrot will not save it again.An example:
taskScheduler.<MyService>schedule(id, OffsetDateTime.now().plusHours(5), x -> x.doWork());- Type Parameters:
S- generic type for IocTaskLambda- Parameters:
id- the uuid with which to save the taskoffsetDateTime- The moment in time at which the task will be enqueued.iocTask- the lambda which defines the fire-and-forget task- Returns:
- the id of the Task
-
schedule
public TaskId schedule(LocalDateTime localDateTime, TaskLambda task)
Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.An example:
MyService service = new MyService(); taskScheduler.schedule(LocalDateTime.now().plusHours(5), () -> service.doWork());- Parameters:
localDateTime- the moment in time at which the task will be enqueued. It will use the systemDefault ZoneId to transform it to an UTC Instanttask- the lambda which defines the fire-and-forget task- Returns:
- the id of the Task
-
schedule
public TaskId schedule(UUID id, LocalDateTime localDateTime, TaskLambda task)
Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time. If a task with that id already exists, Carrot will not save it again.An example:
MyService service = new MyService(); taskScheduler.schedule(id, LocalDateTime.now().plusHours(5), () -> service.doWork());- Parameters:
id- the uuid with which to save the tasklocalDateTime- the moment in time at which the task will be enqueued. It will use the systemDefault ZoneId to transform it to an UTC Instanttask- the lambda which defines the fire-and-forget task- Returns:
- the id of the Task
-
schedule
public <S> TaskId schedule(LocalDateTime localDateTime, IocTaskLambda<S> iocTask)
Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time. The IoC container will be used to resolveMyService.An example:
taskScheduler.<MyService>schedule(LocalDateTime.now().plusHours(5), x -> x.doWork());- Type Parameters:
S- generic type for IocTaskLambda- Parameters:
localDateTime- the moment in time at which the task will be enqueued. It will use the systemDefault ZoneId to transform it to an UTC InstantiocTask- the lambda which defines the fire-and-forget task- Returns:
- the id of the Task
-
schedule
public <S> TaskId schedule(UUID id, LocalDateTime localDateTime, IocTaskLambda<S> iocTask)
Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time. The IoC container will be used to resolveMyService. If a task with that id already exists, Carrot will not save it again.An example:
taskScheduler.<MyService>schedule(LocalDateTime.now().plusHours(5), x -> x.doWork());- Type Parameters:
S- generic type for IocTaskLambda- Parameters:
id- the uuid with which to save the tasklocalDateTime- the moment in time at which the task will be enqueued. It will use the systemDefault ZoneId to transform it to an UTC InstantiocTask- the lambda which defines the fire-and-forget task- Returns:
- the id of the Task
-
schedule
public TaskId schedule(Instant instant, TaskLambda task)
Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time.An example:
MyService service = new MyService(); taskScheduler.schedule(Instant.now().plusHours(5), () -> service.doWork());- Parameters:
instant- the moment in time at which the task will be enqueued.task- the lambda which defines the fire-and-forget task- Returns:
- the id of the Task
-
schedule
public TaskId schedule(UUID id, Instant instant, TaskLambda task)
Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time. If a task with that id already exists, Carrot will not save it again.An example:
MyService service = new MyService(); taskScheduler.schedule(id, Instant.now().plusHours(5), () -> service.doWork());- Parameters:
id- the uuid with which to save the taskinstant- the moment in time at which the task will be enqueued.task- the lambda which defines the fire-and-forget task- Returns:
- the id of the Task
-
schedule
public <S> TaskId schedule(Instant instant, IocTaskLambda<S> iocTask)
Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time. The IoC container will be used to resolveMyService.An example:
taskScheduler.<MyService>schedule(Instant.now().plusHours(5), x -> x.doWork());- Type Parameters:
S- generic type for IocTaskLambda- Parameters:
instant- the moment in time at which the task will be enqueued.iocTask- the lambda which defines the fire-and-forget task- Returns:
- the id of the Task
-
schedule
public <S> TaskId schedule(UUID id, Instant instant, IocTaskLambda<S> iocTask)
Creates a new fire-and-forget task based on the given lambda and schedules it to be enqueued at the given moment of time. The IoC container will be used to resolveMyService. If a task with that id already exists, Carrot will not save it again.An example:
taskScheduler.<MyService>schedule(id, Instant.now().plusHours(5), x -> x.doWork());- Type Parameters:
S- generic type for IocTaskLambda- Parameters:
id- the uuid with which to save the taskinstant- the moment in time at which the task will be enqueued.iocTask- the lambda which defines the fire-and-forget task- Returns:
- the id of the Task
-
scheduleRecurrently
public String scheduleRecurrently(String cron, TaskLambda task)
Creates a new recurring task based on the given lambda and the given cron expression. The tasks will be scheduled using the systemDefault timezone.An example:
MyService service = new MyService(); taskScheduler.scheduleRecurrently(Cron.daily(), () -> service.doWork());- Parameters:
cron- The cron expression defining when to run this recurring tasktask- the lambda which defines the recurring task- Returns:
- the id of this recurring task which can be used to alter or delete it
- See Also:
Cron
-
scheduleRecurrently
public <S> String scheduleRecurrently(String cron, IocTaskLambda<S> iocTask)
Creates a new recurring task based on the given cron expression and the given lambda. The IoC container will be used to resolveMyService. The tasks will be scheduled using the systemDefault timezone.An example:
taskScheduler.<MyService>scheduleRecurrently(Cron.daily(), x -> x.doWork());- Type Parameters:
S- generic type for IocTaskLambda- Parameters:
cron- The cron expression defining when to run this recurring taskiocTask- the lambda which defines the recurring task- Returns:
- the id of this recurring task which can be used to alter or delete it
- See Also:
Cron
-
scheduleRecurrently
public String scheduleRecurrently(String id, String cron, TaskLambda task)
Creates a new or alters the existing recurring task based on the given id, cron expression and lambda. The tasks will be scheduled using the systemDefault timezoneAn example:
MyService service = new MyService(); taskScheduler.scheduleRecurrently("my-recurring-task", Cron.daily(), () -> service.doWork());- Parameters:
id- the id of this recurring task which can be used to alter or delete itcron- The cron expression defining when to run this recurring tasktask- the lambda which defines the recurring task- Returns:
- the id of this recurring task which can be used to alter or delete it
- See Also:
Cron
-
scheduleRecurrently
public <S> String scheduleRecurrently(String id, String cron, IocTaskLambda<S> iocTask)
Creates a new or alters the existing recurring task based on the given id, cron expression and lambda. The IoC container will be used to resolveMyService. The tasks will be scheduled using the systemDefault timezoneAn example:
taskScheduler.<MyService>scheduleRecurrently("my-recurring-task", Cron.daily()), x -> x.doWork();- Type Parameters:
S- generic type for IocTaskLambda- Parameters:
id- the id of this recurring task which can be used to alter or delete itcron- The cron expression defining when to run this recurring taskiocTask- the lambda which defines the recurring task- Returns:
- the id of this recurring task which can be used to alter or delete it
- See Also:
Cron
-
scheduleRecurrently
public String scheduleRecurrently(String id, String cron, ZoneId zoneId, TaskLambda task)
Creates a new or alters the existing recurring task based on the given id, cron expression,ZoneIdand lambda.An example:
MyService service = new MyService(); taskScheduler.scheduleRecurrently("my-recurring-task", Cron.daily(), ZoneId.of("Europe/Brussels"), () -> service.doWork());- Parameters:
id- the id of this recurring task which can be used to alter or delete itcron- The cron expression defining when to run this recurring taskzoneId- The zoneId (timezone) of when to run this recurring tasktask- the lambda which defines the recurring task- Returns:
- the id of this recurring task which can be used to alter or delete it
- See Also:
Cron
-
scheduleRecurrently
public <S> String scheduleRecurrently(String id, String cron, ZoneId zoneId, IocTaskLambda<S> iocTask)
Creates a new or alters the existing recurring task based on the given id, cron expression,ZoneIdand lambda. The IoC container will be used to resolveMyService.An example:
taskScheduler.<MyService>scheduleRecurrently("my-recurring-task", Cron.daily(), ZoneId.of("Europe/Brussels"), x -> x.doWork());- Type Parameters:
S- generic type for IocTaskLambda- Parameters:
id- the id of this recurring task which can be used to alter or delete itcron- The cron expression defining when to run this recurring taskzoneId- The zoneId (timezone) of when to run this recurring taskiocTask- the lambda which defines the recurring task- Returns:
- the id of this recurring task which can be used to alter or delete it
- See Also:
Cron
-
scheduleRecurrently
public String scheduleRecurrently(Duration duration, TaskLambda task)
Creates a new recurring task based on the given duration and the given lambda. The first run of this recurring task will happen after the given duration unless your duration is smaller or equal than your backgroundTaskServer pollInterval.An example:
MyService service = new MyService(); BackgroundTask.scheduleRecurrently(Duration.parse("P5D"), () -> service.doWork());- Parameters:
duration- the duration defining the time between each instance of this recurring task.task- the lambda which defines the recurring task- Returns:
- the id of this recurring task which can be used to alter or delete it
-
scheduleRecurrently
public <S> String scheduleRecurrently(Duration duration, IocTaskLambda<S> iocTask)
Creates a new recurring task based on the given duration and the given lambda. The IoC container will be used to resolveMyService. The first run of this recurring task will happen after the given duration unless your duration is smaller or equal than your backgroundTaskServer pollInterval.An example:
BackgroundTask.<MyService>scheduleRecurrently(Duration.parse("P5D"), x -> x.doWork());- Type Parameters:
S- generic type for IocTaskLambda- Parameters:
duration- the duration defining the time between each instance of this recurring taskiocTask- the lambda which defines the recurring task- Returns:
- the id of this recurring task which can be used to alter or delete it
-
scheduleRecurrently
public String scheduleRecurrently(String id, Duration duration, TaskLambda task)
Creates a new or alters the existing recurring task based on the given id, duration and lambda. The first run of this recurring task will happen after the given duration unless your duration is smaller or equal than your backgroundTaskServer pollInterval.An example:
MyService service = new MyService(); BackgroundTask.scheduleRecurrently("my-recurring-task", Duration.parse("P5D"), () -> service.doWork());- Parameters:
id- the id of this recurring task which can be used to alter or delete itduration- the duration defining the time between each instance of this recurring tasktask- the lambda which defines the recurring task- Returns:
- the id of this recurring task which can be used to alter or delete it
-
scheduleRecurrently
public <S> String scheduleRecurrently(String id, Duration duration, IocTaskLambda<S> iocTask)
Creates a new or alters the existing recurring task based on the given id, duration and lambda. The IoC container will be used to resolveMyService. The first run of this recurring task will happen after the given duration unless your duration is smaller or equal than your backgroundTaskServer pollInterval.An example:
BackgroundTask.<MyService>scheduleRecurrently("my-recurring-task", Duration.parse("P5D"), x -> x.doWork());- Type Parameters:
S- generic type for IocTaskLambda- Parameters:
id- the id of this recurring task which can be used to alter or delete itduration- the duration defining the time between each instance of this recurring taskiocTask- the lambda which defines the recurring task- Returns:
- the id of this recurring task which can be used to alter or delete it
-
-