Package cn.boboweike.carrot.scheduling
Class BackgroundTask
- java.lang.Object
-
- cn.boboweike.carrot.scheduling.BackgroundTask
-
public class BackgroundTask extends Object
Provides static methods for creating fire-and-forget, delayed and recurring tasks as well as to delete existing background tasks. If you prefer not to use a static accessor, you can inject theTaskSchedulerwhich exposes the same methods.- Author:
- Ronald Dehuysser
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voiddelete(TaskId taskId)static voiddelete(String id)Deletes the recurring task based on the given id.static voiddelete(UUID id)Deletes a task and sets its state to DELETED.static <S> TaskIdenqueue(IocTaskLambda<S> iocTask)Creates a new fire-and-forget task based on a given lambda.static TaskIdenqueue(TaskLambda task)Creates a new fire-and-forget task based on a given lambda.static <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.static <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.static <S> TaskIdenqueue(UUID id, IocTaskLambda<S> iocTask)Creates a new fire-and-forget task based on a given lambda.static TaskIdenqueue(UUID id, TaskLambda task)Creates a new fire-and-forget task based on a given lambda.static <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.static 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.static <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.static 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.static <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.static 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.static <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.static 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.static <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.static 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.static <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.static 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.static <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.static 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.static <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.static 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.static <S> StringscheduleRecurrently(String cron, IocTaskLambda<S> iocTask)Creates a new recurring task based on the given cron expression and the given lambda.static StringscheduleRecurrently(String cron, TaskLambda task)Creates a new recurring task based on the given cron expression and the given lambda.static <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.static 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.static <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.static 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.static <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.static StringscheduleRecurrently(String id, Duration duration, TaskLambda task)Creates a new or alters the existing recurring task based on the given id, duration and lambda.static <S> StringscheduleRecurrently(Duration duration, IocTaskLambda<S> iocTask)Creates a new recurring task based on the given duration and the given lambda.static StringscheduleRecurrently(Duration duration, TaskLambda task)Creates a new recurring task based on the given duration and the given lambda.static voidsetTaskScheduler(TaskScheduler taskScheduler)
-
-
-
Method Detail
-
enqueue
public static TaskId enqueue(TaskLambda task)
Creates a new fire-and-forget task based on a given lambda.An example:
MyService service = new MyService(); BackgroundTask.enqueue(() -> service.doWork());- Parameters:
task- the lambda which defines the fire-and-forget task- Returns:
- the id of the task
-
enqueue
public static TaskId enqueue(UUID id, TaskLambda task)
Creates a new fire-and-forget task based on a given lambda. If a task with that id already exists, Carrot will not save it again.An example:
MyService service = new MyService(); BackgroundTask.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 static <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(); BackgroundTask.enqueue(workStream, (uuid) -> service.doWork(uuid));- Type Parameters:
T- generic type for the Stream- 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 static <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:
BackgroundTask.<MyService>enqueue(x -> x.doWork());- Type Parameters:
S- generic type for the IocTaskLambda- Parameters:
iocTask- the lambda which defines the fire-and-forget task- Returns:
- the id of the task
-
enqueue
public static <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:
BackgroundTask.<MyService>enqueue(id, x -> x.doWork());- Type Parameters:
S- generic type for the 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 static <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(); BackgroundTask.<MyService, UUID>enqueue(workStream, (x, uuid) -> x.doWork(uuid));- Type Parameters:
S- generic type for the IocTaskLambdaFromStreamT- generic type for the 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 static 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(); BackgroundTask.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 static 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(); BackgroundTask.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 static <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:
BackgroundTask.<MyService>schedule(ZonedDateTime.now().plusHours(5), x -> x.doWork());- Type Parameters:
S- generic type for the 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 static <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:
BackgroundTask.<MyService>schedule(id, ZonedDateTime.now().plusHours(5), x -> x.doWork());- Type Parameters:
S- generic type for the 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 static 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(); BackgroundTask.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 static 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(); BackgroundTask.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 static <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:
BackgroundTask.<MyService>schedule(id, OffsetDateTime.now().plusHours(5), x -> x.doWork());- Type Parameters:
S- generic type for the 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 static <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:
BackgroundTask.<MyService>schedule(id, OffsetDateTime.now().plusHours(5), x -> x.doWork());- Type Parameters:
S- generic type for the 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 static 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(); BackgroundTask.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 static 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(); BackgroundTask.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 static <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:
BackgroundTask.<MyService>schedule(LocalDateTime.now().plusHours(5), x -> x.doWork());- Type Parameters:
S- generic type for the 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 static <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:
BackgroundTask.<MyService>schedule(id, LocalDateTime.now().plusHours(5), x -> x.doWork());- Type Parameters:
S- generic type for the 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 static 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(); BackgroundTask.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 static 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(); BackgroundTask.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 static <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:
BackgroundTask.<MyService>schedule(Instant.now().plusHours(5), x -> x.doWork());- Type Parameters:
S- Generic type for the 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 static <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:
BackgroundTask.<MyService>schedule(id, Instant.now().plusHours(5), x -> x.doWork());- Type Parameters:
S- Generic type for the 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
-
delete
public static void delete(UUID id)
Deletes a task and sets its state to DELETED. If the task is being processed, it will be interrupted.- Parameters:
id- the id of the task
-
delete
public static void delete(TaskId taskId)
- Parameters:
taskId- the id of the task- See Also:
delete(UUID)
-
scheduleRecurrently
public static String scheduleRecurrently(String cron, TaskLambda task)
Creates a new recurring task based on the given cron expression and the given lambda. The tasks will be scheduled using the systemDefault timezone.An example:
MyService service = new MyService(); BackgroundTask.scheduleRecurrently(Cron.daily(), () -> service.doWork());- Parameters:
cron- The cron expression defining when to run this recurring tasktask- the lambda which defines the fire-and-forget task- Returns:
- the id of this recurring task which can be used to alter or delete it
- See Also:
Cron
-
scheduleRecurrently
public static <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:
BackgroundTask.<MyService>scheduleRecurrently(Cron.daily(), x -> x.doWork());- Type Parameters:
S- Generic type for the IocTaskLambda- Parameters:
cron- The cron expression defining when to run this recurring taskiocTask- the lambda which defines the fire-and-forget task- Returns:
- the id of this recurring task which can be used to alter or delete it
- See Also:
Cron
-
scheduleRecurrently
public static 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(); BackgroundTask.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 fire-and-forget task- Returns:
- the id of this recurring task which can be used to alter or delete it
- See Also:
Cron
-
scheduleRecurrently
public static <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:
BackgroundTask.<MyService>scheduleRecurrently("my-recurring-task", Cron.daily(), x -> x.doWork());- Type Parameters:
S- Generic type for the 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 fire-and-forget task- Returns:
- the id of this recurring task which can be used to alter or delete it
- See Also:
Cron
-
scheduleRecurrently
public static 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(); BackgroundTask.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 fire-and-forget task- Returns:
- the id of this recurring task which can be used to alter or delete it
- See Also:
Cron
-
scheduleRecurrently
public static <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:
BackgroundTask.<MyService>scheduleRecurrently("my-recurring-task", Cron.daily(), ZoneId.of("Europe/Brussels"), x -> x.doWork());- Type Parameters:
S- Generic type for the 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 fire-and-forget task- Returns:
- the id of this recurring task which can be used to alter or delete it
- See Also:
Cron
-
scheduleRecurrently
public static 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 tasktask- the lambda which defines the fire-and-forget task- Returns:
- the id of this recurring task which can be used to alter or delete it
-
scheduleRecurrently
public static <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 the IocTaskLambda- Parameters:
duration- the duration defining the time between each instance of this recurring taskiocTask- the lambda which defines the fire-and-forget task- Returns:
- the id of this recurring task which can be used to alter or delete it
-
scheduleRecurrently
public static 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 fire-and-forget task- Returns:
- the id of this recurring task which can be used to alter or delete it
-
scheduleRecurrently
public static <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 the 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 fire-and-forget task- Returns:
- the id of this recurring task which can be used to alter or delete it
-
delete
public static void delete(String id)
Deletes the recurring task based on the given id.An example:
BackgroundTask.delete("my-recurring-task"));- Parameters:
id- the id of the recurring task to delete
-
setTaskScheduler
public static void setTaskScheduler(TaskScheduler taskScheduler)
-
-