Class JobScheduler


  • public class JobScheduler
    extends AbstractJobScheduler
    Provides methods for creating fire-and-forget, delayed and recurring jobs as well as to delete existing background jobs.

    This JobScheduler allows to schedule jobs by means of a Java 8 lambda which is analyzed.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <S,​T>
      void
      enqueue​(java.util.stream.Stream<T> input, IocJobLambdaFromStream<S,​T> iocJobFromStream)
      Creates new fire-and-forget jobs for each item in the input stream using the lambda passed as jobFromStream.
      <T> void enqueue​(java.util.stream.Stream<T> input, JobLambdaFromStream<T> jobFromStream)
      Creates new fire-and-forget jobs for each item in the input stream using the lambda passed as jobFromStream.
      <S> JobId enqueue​(java.util.UUID id, IocJobLambda<S> iocJob)
      Creates a new fire-and-forget job based on a given lambda.
      JobId enqueue​(java.util.UUID id, JobLambda job)
      Creates a new fire-and-forget job based on the given lambda.
      <S> JobId enqueue​(IocJobLambda<S> iocJob)
      Creates a new fire-and-forget job based on a given lambda.
      JobId enqueue​(JobLambda job)
      Creates a new fire-and-forget job based on a given lambda.
      <S> JobId schedule​(java.time.Instant instant, IocJobLambda<S> iocJob)
      Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
      JobId schedule​(java.time.Instant instant, JobLambda job)
      Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
      <S> JobId schedule​(java.time.LocalDateTime localDateTime, IocJobLambda<S> iocJob)
      Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
      JobId schedule​(java.time.LocalDateTime localDateTime, JobLambda job)
      Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
      <S> JobId schedule​(java.time.OffsetDateTime offsetDateTime, IocJobLambda<S> iocJob)
      Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
      JobId schedule​(java.time.OffsetDateTime offsetDateTime, JobLambda job)
      Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
      <S> JobId schedule​(java.time.ZonedDateTime zonedDateTime, IocJobLambda<S> iocJob)
      Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
      JobId schedule​(java.time.ZonedDateTime zonedDateTime, JobLambda job)
      Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
      <S> JobId schedule​(java.util.UUID id, java.time.Instant instant, IocJobLambda<S> iocJob)
      Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
      JobId schedule​(java.util.UUID id, java.time.Instant instant, JobLambda job)
      Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
      <S> JobId schedule​(java.util.UUID id, java.time.LocalDateTime localDateTime, IocJobLambda<S> iocJob)
      Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
      JobId schedule​(java.util.UUID id, java.time.LocalDateTime localDateTime, JobLambda job)
      Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
      <S> JobId schedule​(java.util.UUID id, java.time.OffsetDateTime offsetDateTime, IocJobLambda<S> iocJob)
      Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
      JobId schedule​(java.util.UUID id, java.time.OffsetDateTime offsetDateTime, JobLambda job)
      Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
      <S> JobId schedule​(java.util.UUID id, java.time.ZonedDateTime zonedDateTime, IocJobLambda<S> iocJob)
      Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
      JobId schedule​(java.util.UUID id, java.time.ZonedDateTime zonedDateTime, JobLambda job)
      Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
      <S> java.lang.String scheduleRecurrently​(java.lang.String id, java.lang.String cron, java.time.ZoneId zoneId, IocJobLambda<S> iocJob)
      Creates a new or alters the existing recurring job based on the given id, cron expression, ZoneId and lambda.
      java.lang.String scheduleRecurrently​(java.lang.String id, java.lang.String cron, java.time.ZoneId zoneId, JobLambda job)
      Creates a new or alters the existing recurring job based on the given id, cron expression, ZoneId and lambda.
      <S> java.lang.String scheduleRecurrently​(java.lang.String id, java.lang.String cron, IocJobLambda<S> iocJob)
      Creates a new or alters the existing recurring job based on the given id, cron expression and lambda.
      java.lang.String scheduleRecurrently​(java.lang.String id, java.lang.String cron, JobLambda job)
      Creates a new or alters the existing recurring job based on the given id, cron expression and lambda.
      <S> java.lang.String scheduleRecurrently​(java.lang.String id, java.time.Duration duration, IocJobLambda<S> iocJob)
      Creates a new or alters the existing recurring job based on the given id, duration and lambda.
      java.lang.String scheduleRecurrently​(java.lang.String id, java.time.Duration duration, JobLambda job)
      Creates a new or alters the existing recurring job based on the given id, duration and lambda.
      <S> java.lang.String scheduleRecurrently​(java.lang.String cron, IocJobLambda<S> iocJob)
      Creates a new recurring job based on the given cron expression and the given lambda.
      java.lang.String scheduleRecurrently​(java.lang.String cron, JobLambda job)
      Creates a new recurring job based on the given lambda and the given cron expression.
      <S> java.lang.String scheduleRecurrently​(java.time.Duration duration, IocJobLambda<S> iocJob)
      Creates a new recurring job based on the given duration and the given lambda.
      java.lang.String scheduleRecurrently​(java.time.Duration duration, JobLambda job)
      Creates a new recurring job based on the given duration and the given lambda.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JobScheduler

        public JobScheduler​(StorageProvider storageProvider)
        Creates a new JobScheduler using the provided storageProvider
        Parameters:
        storageProvider - the storageProvider to use
      • JobScheduler

        public JobScheduler​(StorageProvider storageProvider,
                            java.util.List<JobFilter> jobFilters)
        Creates a new JobScheduler using the provided storageProvider and the list of JobFilters that will be used for every background job
        Parameters:
        storageProvider - the storageProvider to use
        jobFilters - list of jobFilters that will be used for every job
    • Method Detail

      • enqueue

        public JobId enqueue​(JobLambda job)
        Creates a new fire-and-forget job based on a given lambda.
        An example:
        
                    MyService service = new MyService();
                    jobScheduler.enqueue(() -> service.doWork());
               
        Parameters:
        job - the lambda which defines the fire-and-forget job
        Returns:
        the id of the job
      • enqueue

        public JobId enqueue​(java.util.UUID id,
                             JobLambda job)
        Creates a new fire-and-forget job based on the given lambda. If a job with that id already exists, JobRunr will not save it again.
        An example:
        
                    MyService service = new MyService();
                    jobScheduler.enqueue(id, () -> service.doWork());
               
        Parameters:
        id - the uuid with which to save the job
        job - the lambda which defines the fire-and-forget job
        Returns:
        the id of the job
      • enqueue

        public <T> void enqueue​(java.util.stream.Stream<T> input,
                                JobLambdaFromStream<T> jobFromStream)
        Creates new fire-and-forget jobs for each item in the input stream using the lambda passed as jobFromStream.
        An example:
        
              MyService service = new MyService();
              Stream<UUID> workStream = getWorkStream();
              jobScheduler.enqueue(workStream, (uuid) -> service.doWork(uuid));
         
        Parameters:
        input - the stream of items for which to create fire-and-forget jobs
        jobFromStream - the lambda which defines the fire-and-forget job to create for each item in the input
      • enqueue

        public <S> JobId enqueue​(IocJobLambda<S> iocJob)
        Creates a new fire-and-forget job based on a given lambda. The IoC container will be used to resolve MyService.
        An example:
        
                    jobScheduler.<MyService>enqueue(x -> x.doWork());
               
        Parameters:
        iocJob - the lambda which defines the fire-and-forget job
        Returns:
        the id of the job
      • enqueue

        public <S> JobId enqueue​(java.util.UUID id,
                                 IocJobLambda<S> iocJob)
        Creates a new fire-and-forget job based on a given lambda. The IoC container will be used to resolve MyService. If a job with that id already exists, JobRunr will not save it again.
        An example:
        
                    jobScheduler.<MyService>enqueue(id, x -> x.doWork());
               
        Parameters:
        id - the uuid with which to save the job
        iocJob - the lambda which defines the fire-and-forget job
        Returns:
        the id of the job
      • enqueue

        public <S,​T> void enqueue​(java.util.stream.Stream<T> input,
                                        IocJobLambdaFromStream<S,​T> iocJobFromStream)
        Creates new fire-and-forget jobs for each item in the input stream using the lambda passed as jobFromStream. The IoC container will be used to resolve MyService.
        An example:
        
              Stream<UUID> workStream = getWorkStream();
              jobScheduler.<MyService, UUID>enqueue(workStream, (x, uuid) -> x.doWork(uuid));
         
        Parameters:
        input - the stream of items for which to create fire-and-forget jobs
        iocJobFromStream - the lambda which defines the fire-and-forget job to create for each item in the input
      • schedule

        public JobId schedule​(java.time.ZonedDateTime zonedDateTime,
                              JobLambda job)
        Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
        An example:
        
              MyService service = new MyService();
              jobScheduler.schedule(ZonedDateTime.now().plusHours(5), () -> service.doWork());
         
        Parameters:
        zonedDateTime - the moment in time at which the job will be enqueued.
        job - the lambda which defines the fire-and-forget job
        Returns:
        the id of the Job
      • schedule

        public JobId schedule​(java.util.UUID id,
                              java.time.ZonedDateTime zonedDateTime,
                              JobLambda job)
        Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time. If a job with that id already exists, JobRunr will not save it again.
        An example:
        
              MyService service = new MyService();
              jobScheduler.schedule(id, ZonedDateTime.now().plusHours(5), () -> service.doWork());
         
        Parameters:
        id - the uuid with which to save the job
        zonedDateTime - the moment in time at which the job will be enqueued.
        job - the lambda which defines the fire-and-forget job
        Returns:
        the id of the Job
      • schedule

        public <S> JobId schedule​(java.time.ZonedDateTime zonedDateTime,
                                  IocJobLambda<S> iocJob)
        Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time. The IoC container will be used to resolve MyService.
        An example:
        
              jobScheduler.<MyService>schedule(ZonedDateTime.now().plusHours(5), x -> x.doWork());
         
        Parameters:
        zonedDateTime - the moment in time at which the job will be enqueued.
        iocJob - the lambda which defines the fire-and-forget job
        Returns:
        the id of the Job
      • schedule

        public <S> JobId schedule​(java.util.UUID id,
                                  java.time.ZonedDateTime zonedDateTime,
                                  IocJobLambda<S> iocJob)
        Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time. The IoC container will be used to resolve MyService. If a job with that id already exists, JobRunr will not save it again.
        An example:
        
              jobScheduler.<MyService>schedule(id, ZonedDateTime.now().plusHours(5), x -> x.doWork());
         
        Parameters:
        id - the uuid with which to save the job
        zonedDateTime - the moment in time at which the job will be enqueued.
        iocJob - the lambda which defines the fire-and-forget job
        Returns:
        the id of the Job
      • schedule

        public JobId schedule​(java.time.OffsetDateTime offsetDateTime,
                              JobLambda job)
        Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
        An example:
        
              MyService service = new MyService();
              jobScheduler.schedule(OffsetDateTime.now().plusHours(5), () -> service.doWork());
         
        Parameters:
        offsetDateTime - The moment in time at which the job will be enqueued.
        job - the lambda which defines the fire-and-forget job
        Returns:
        the id of the Job
      • schedule

        public JobId schedule​(java.util.UUID id,
                              java.time.OffsetDateTime offsetDateTime,
                              JobLambda job)
        Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time. If a job with that id already exists, JobRunr will not save it again.
        An example:
        
              MyService service = new MyService();
              jobScheduler.schedule(id, OffsetDateTime.now().plusHours(5), () -> service.doWork());
         
        Parameters:
        id - the uuid with which to save the job
        offsetDateTime - The moment in time at which the job will be enqueued.
        job - the lambda which defines the fire-and-forget job
        Returns:
        the id of the Job
      • schedule

        public <S> JobId schedule​(java.time.OffsetDateTime offsetDateTime,
                                  IocJobLambda<S> iocJob)
        Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time. The IoC container will be used to resolve MyService.
        An example:
        
              jobScheduler.<MyService>schedule(OffsetDateTime.now().plusHours(5), x -> x.doWork());
         
        Parameters:
        offsetDateTime - The moment in time at which the job will be enqueued.
        iocJob - the lambda which defines the fire-and-forget job
        Returns:
        the id of the Job
      • schedule

        public <S> JobId schedule​(java.util.UUID id,
                                  java.time.OffsetDateTime offsetDateTime,
                                  IocJobLambda<S> iocJob)
        Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time. The IoC container will be used to resolve MyService. If a job with that id already exists, JobRunr will not save it again.
        An example:
        
              jobScheduler.<MyService>schedule(id, OffsetDateTime.now().plusHours(5), x -> x.doWork());
         
        Parameters:
        id - the uuid with which to save the job
        offsetDateTime - The moment in time at which the job will be enqueued.
        iocJob - the lambda which defines the fire-and-forget job
        Returns:
        the id of the Job
      • schedule

        public JobId schedule​(java.time.LocalDateTime localDateTime,
                              JobLambda job)
        Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
        An example:
        
              MyService service = new MyService();
              jobScheduler.schedule(LocalDateTime.now().plusHours(5), () -> service.doWork());
         
        Parameters:
        localDateTime - the moment in time at which the job will be enqueued. It will use the systemDefault ZoneId to transform it to an UTC Instant
        job - the lambda which defines the fire-and-forget job
        Returns:
        the id of the Job
      • schedule

        public JobId schedule​(java.util.UUID id,
                              java.time.LocalDateTime localDateTime,
                              JobLambda job)
        Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time. If a job with that id already exists, JobRunr will not save it again.
        An example:
        
              MyService service = new MyService();
              jobScheduler.schedule(id, LocalDateTime.now().plusHours(5), () -> service.doWork());
         
        Parameters:
        id - the uuid with which to save the job
        localDateTime - the moment in time at which the job will be enqueued. It will use the systemDefault ZoneId to transform it to an UTC Instant
        job - the lambda which defines the fire-and-forget job
        Returns:
        the id of the Job
      • schedule

        public <S> JobId schedule​(java.time.LocalDateTime localDateTime,
                                  IocJobLambda<S> iocJob)
        Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time. The IoC container will be used to resolve MyService.
        An example:
        
              jobScheduler.<MyService>schedule(LocalDateTime.now().plusHours(5), x -> x.doWork());
         
        Parameters:
        localDateTime - the moment in time at which the job will be enqueued. It will use the systemDefault ZoneId to transform it to an UTC Instant
        iocJob - the lambda which defines the fire-and-forget job
        Returns:
        the id of the Job
      • schedule

        public <S> JobId schedule​(java.util.UUID id,
                                  java.time.LocalDateTime localDateTime,
                                  IocJobLambda<S> iocJob)
        Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time. The IoC container will be used to resolve MyService. If a job with that id already exists, JobRunr will not save it again.
        An example:
        
              jobScheduler.<MyService>schedule(LocalDateTime.now().plusHours(5), x -> x.doWork());
         
        Parameters:
        id - the uuid with which to save the job
        localDateTime - the moment in time at which the job will be enqueued. It will use the systemDefault ZoneId to transform it to an UTC Instant
        iocJob - the lambda which defines the fire-and-forget job
        Returns:
        the id of the Job
      • schedule

        public JobId schedule​(java.time.Instant instant,
                              JobLambda job)
        Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time.
        An example:
        
              MyService service = new MyService();
              jobScheduler.schedule(Instant.now().plusHours(5), () -> service.doWork());
         
        Parameters:
        instant - the moment in time at which the job will be enqueued.
        job - the lambda which defines the fire-and-forget job
        Returns:
        the id of the Job
      • schedule

        public JobId schedule​(java.util.UUID id,
                              java.time.Instant instant,
                              JobLambda job)
        Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time. If a job with that id already exists, JobRunr will not save it again.
        An example:
        
              MyService service = new MyService();
              jobScheduler.schedule(id, Instant.now().plusHours(5), () -> service.doWork());
         
        Parameters:
        id - the uuid with which to save the job
        instant - the moment in time at which the job will be enqueued.
        job - the lambda which defines the fire-and-forget job
        Returns:
        the id of the Job
      • schedule

        public <S> JobId schedule​(java.time.Instant instant,
                                  IocJobLambda<S> iocJob)
        Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time. The IoC container will be used to resolve MyService.
        An example:
        
              jobScheduler.<MyService>schedule(Instant.now().plusHours(5), x -> x.doWork());
         
        Parameters:
        instant - the moment in time at which the job will be enqueued.
        iocJob - the lambda which defines the fire-and-forget job
        Returns:
        the id of the Job
      • schedule

        public <S> JobId schedule​(java.util.UUID id,
                                  java.time.Instant instant,
                                  IocJobLambda<S> iocJob)
        Creates a new fire-and-forget job based on the given lambda and schedules it to be enqueued at the given moment of time. The IoC container will be used to resolve MyService. If a job with that id already exists, JobRunr will not save it again.
        An example:
        
              jobScheduler.<MyService>schedule(id, Instant.now().plusHours(5), x -> x.doWork());
         
        Parameters:
        id - the uuid with which to save the job
        instant - the moment in time at which the job will be enqueued.
        iocJob - the lambda which defines the fire-and-forget job
        Returns:
        the id of the Job
      • scheduleRecurrently

        public java.lang.String scheduleRecurrently​(java.lang.String cron,
                                                    JobLambda job)
        Creates a new recurring job based on the given lambda and the given cron expression. The jobs will be scheduled using the systemDefault timezone.
        An example:
        
              MyService service = new MyService();
              jobScheduler.scheduleRecurrently(Cron.daily(), () -> service.doWork());
         
        Parameters:
        cron - The cron expression defining when to run this recurring job
        job - the lambda which defines the recurring job
        Returns:
        the id of this recurring job which can be used to alter or delete it
        See Also:
        Cron
      • scheduleRecurrently

        public <S> java.lang.String scheduleRecurrently​(java.lang.String cron,
                                                        IocJobLambda<S> iocJob)
        Creates a new recurring job based on the given cron expression and the given lambda. The IoC container will be used to resolve MyService. The jobs will be scheduled using the systemDefault timezone.
        An example:
        
              jobScheduler.<MyService>scheduleRecurrently(Cron.daily(), x -> x.doWork());
         
        Parameters:
        cron - The cron expression defining when to run this recurring job
        iocJob - the lambda which defines the recurring job
        Returns:
        the id of this recurring job which can be used to alter or delete it
        See Also:
        Cron
      • scheduleRecurrently

        public java.lang.String scheduleRecurrently​(java.lang.String id,
                                                    java.lang.String cron,
                                                    JobLambda job)
        Creates a new or alters the existing recurring job based on the given id, cron expression and lambda. The jobs will be scheduled using the systemDefault timezone
        An example:
        
              MyService service = new MyService();
              jobScheduler.scheduleRecurrently("my-recurring-job", Cron.daily(), () -> service.doWork());
         
        Parameters:
        id - the id of this recurring job which can be used to alter or delete it
        cron - The cron expression defining when to run this recurring job
        job - the lambda which defines the recurring job
        Returns:
        the id of this recurring job which can be used to alter or delete it
        See Also:
        Cron
      • scheduleRecurrently

        public <S> java.lang.String scheduleRecurrently​(java.lang.String id,
                                                        java.lang.String cron,
                                                        IocJobLambda<S> iocJob)
        Creates a new or alters the existing recurring job based on the given id, cron expression and lambda. The IoC container will be used to resolve MyService. The jobs will be scheduled using the systemDefault timezone
        An example:
        
              jobScheduler.<MyService>scheduleRecurrently("my-recurring-job", Cron.daily()),  x -> x.doWork();
         
        Parameters:
        id - the id of this recurring job which can be used to alter or delete it
        cron - The cron expression defining when to run this recurring job
        iocJob - the lambda which defines the recurring job
        Returns:
        the id of this recurring job which can be used to alter or delete it
        See Also:
        Cron
      • scheduleRecurrently

        public java.lang.String scheduleRecurrently​(java.lang.String id,
                                                    java.lang.String cron,
                                                    java.time.ZoneId zoneId,
                                                    JobLambda job)
        Creates a new or alters the existing recurring job based on the given id, cron expression, ZoneId and lambda.
        An example:
        
              MyService service = new MyService();
              jobScheduler.scheduleRecurrently("my-recurring-job", Cron.daily(), ZoneId.of("Europe/Brussels"), () -> service.doWork());
         
        Parameters:
        id - the id of this recurring job which can be used to alter or delete it
        cron - The cron expression defining when to run this recurring job
        zoneId - The zoneId (timezone) of when to run this recurring job
        job - the lambda which defines the recurring job
        Returns:
        the id of this recurring job which can be used to alter or delete it
        See Also:
        Cron
      • scheduleRecurrently

        public <S> java.lang.String scheduleRecurrently​(java.lang.String id,
                                                        java.lang.String cron,
                                                        java.time.ZoneId zoneId,
                                                        IocJobLambda<S> iocJob)
        Creates a new or alters the existing recurring job based on the given id, cron expression, ZoneId and lambda. The IoC container will be used to resolve MyService.
        An example:
        
              jobScheduler.<MyService>scheduleRecurrently("my-recurring-job", Cron.daily(), ZoneId.of("Europe/Brussels"), x -> x.doWork());
         
        Parameters:
        id - the id of this recurring job which can be used to alter or delete it
        cron - The cron expression defining when to run this recurring job
        zoneId - The zoneId (timezone) of when to run this recurring job
        iocJob - the lambda which defines the recurring job
        Returns:
        the id of this recurring job which can be used to alter or delete it
        See Also:
        Cron
      • scheduleRecurrently

        public java.lang.String scheduleRecurrently​(java.time.Duration duration,
                                                    JobLambda job)
        Creates a new recurring job based on the given duration and the given lambda. The first run of this recurring job will happen after the given duration unless your duration is smaller or equal than your backgroundJobServer pollInterval.
        An example:
        
              MyService service = new MyService();
              BackgroundJob.scheduleRecurrently(Duration.parse("P5D"), () -> service.doWork());
         
        Parameters:
        duration - the duration defining the time between each instance of this recurring job.
        job - the lambda which defines the recurring job
        Returns:
        the id of this recurring job which can be used to alter or delete it
      • scheduleRecurrently

        public <S> java.lang.String scheduleRecurrently​(java.time.Duration duration,
                                                        IocJobLambda<S> iocJob)
        Creates a new recurring job based on the given duration and the given lambda. The IoC container will be used to resolve MyService. The first run of this recurring job will happen after the given duration unless your duration is smaller or equal than your backgroundJobServer pollInterval.
        An example:
        
              BackgroundJob.<MyService>scheduleRecurrently(Duration.parse("P5D"), x -> x.doWork());
         
        Parameters:
        duration - the duration defining the time between each instance of this recurring job
        iocJob - the lambda which defines the recurring job
        Returns:
        the id of this recurring job which can be used to alter or delete it
      • scheduleRecurrently

        public java.lang.String scheduleRecurrently​(java.lang.String id,
                                                    java.time.Duration duration,
                                                    JobLambda job)
        Creates a new or alters the existing recurring job based on the given id, duration and lambda. The first run of this recurring job will happen after the given duration unless your duration is smaller or equal than your backgroundJobServer pollInterval.
        An example:
        
              MyService service = new MyService();
              BackgroundJob.scheduleRecurrently("my-recurring-job", Duration.parse("P5D"), () -> service.doWork());
         
        Parameters:
        id - the id of this recurring job which can be used to alter or delete it
        duration - the duration defining the time between each instance of this recurring job
        job - the lambda which defines the recurring job
        Returns:
        the id of this recurring job which can be used to alter or delete it
      • scheduleRecurrently

        public <S> java.lang.String scheduleRecurrently​(java.lang.String id,
                                                        java.time.Duration duration,
                                                        IocJobLambda<S> iocJob)
        Creates a new or alters the existing recurring job based on the given id, duration and lambda. The IoC container will be used to resolve MyService. The first run of this recurring job will happen after the given duration unless your duration is smaller or equal than your backgroundJobServer pollInterval.
        An example:
        
              BackgroundJob.<MyService>scheduleRecurrently("my-recurring-job", Duration.parse("P5D"), x -> x.doWork());
         
        Parameters:
        id - the id of this recurring job which can be used to alter or delete it
        duration - the duration defining the time between each instance of this recurring job
        iocJob - the lambda which defines the recurring job
        Returns:
        the id of this recurring job which can be used to alter or delete it