Class RecurringJobBuilder

java.lang.Object
org.jobrunr.scheduling.RecurringJobBuilder

public class RecurringJobBuilder extends Object
This class is used to build a RecurringJob using a job lambda or a .

You can use it as follows:

A job lambda example:

            MyService service = new MyService();
            jobScheduler.createRecurrently(aRecurringJob()
                                  .withCron("* * 0 * * *")
                                  .withDetails(() -> service.sendMail(toRequestParam, subjectRequestParam, bodyRequestParam));
       
A JobRequest example:

          jobRequestScheduler.createRecurrently(aRecurringJob()
                                .withCron("* * 0 * * *")
                                .withJobRequest(new SendMailRequest(toRequestParam, subjectRequestParam, bodyRequestParam));
     
  • Method Details

    • aRecurringJob

      public static RecurringJobBuilder aRecurringJob()
      Creates a new RecurringJobBuilder instance to create a RecurringJob using a Java 8 lambda.
      Returns:
      a new RecurringJobBuilder instance
    • withId

      public RecurringJobBuilder withId(String jobId)
      Allows to set the id of the recurringJob. If a recurringJob with that id already exists, JobRunr will not save it again.
      Parameters:
      jobId - the recurringJob of the recurringJob
      Returns:
      the same builder instance which provides a fluent api
    • withName

      public RecurringJobBuilder withName(String jobName)
      Allows to set the name of the recurringJob for the dashboard.
      Parameters:
      jobName - the name of the recurringJob for the dashboard
      Returns:
      the same builder instance which provides a fluent api
    • withAmountOfRetries

      public RecurringJobBuilder withAmountOfRetries(int amountOfRetries)
      Allows to specify number of times that the recurringJob should be retried.
      Parameters:
      amountOfRetries - the amount of times the recurringJob should be retried.
      Returns:
      the same builder instance which provides a fluent api
    • withLabels

      public RecurringJobBuilder withLabels(String... labels)
      Allows to provide a set of labels to be shown in the dashboard. A maximum of 3 labels can be provided per job. Each label has a max length of 45 characters.
      Parameters:
      labels - an array of labels to be added to the recurring job
      Returns:
      the same builder instance which provides a fluent api
    • withLabels

      public RecurringJobBuilder withLabels(Set<String> labels)
      Allows to provide a set of labels to be shown in the dashboard. A maximum of 3 labels can be provided per job. Each label has a max length of 45 characters.
      Parameters:
      labels - the set of labels to be added to the recurringJob
      Returns:
      the same builder instance which provides a fluent api
    • withDetails

      public RecurringJobBuilder withDetails(JobLambda jobLambda)
      Allows to provide the job details by means of Java 8 lambda.
      Parameters:
      jobLambda - the lambda which defines the job
      Returns:
      the same builder instance that can be given to the JobScheduler.createRecurrently(RecurringJobBuilder) method
    • withDetails

      public <S> RecurringJobBuilder withDetails(IocJobLambda<S> ioCJobLambda)
      Allows to provide the job details by means of Java 8 lambda. The IoC container will be used to resolve an actual instance of the requested service.
      Parameters:
      ioCJobLambda - the lambda which defines the job
      Returns:
      the same builder instance that can be given to the JobScheduler.createRecurrently(RecurringJobBuilder) method
    • withJobRequest

      public RecurringJobBuilder withJobRequest(JobRequest jobRequest)
      Allows to provide the job details by means of JobRequest.
      Parameters:
      jobRequest - the jobRequest which defines the job.
      Returns:
      the same builder instance that can be given to the JobRequestScheduler.createRecurrently(RecurringJobBuilder) method
    • withCron

      public RecurringJobBuilder withCron(String cron)
      Allows to specify the cron that will be used to create the recurringJobs.
      Parameters:
      cron - the cron that will be used to create the recurringJobs.
      Returns:
      the same builder instance which provides a fluent api
    • withDuration

      public RecurringJobBuilder withDuration(Duration duration)
      Allows to specify the duration that will be used to create the recurringJobs.
      Parameters:
      duration - the duration that will be used to create the recurringJobs.
      Returns:
      the same builder instance which provides a fluent api
    • withZoneId

      public RecurringJobBuilder withZoneId(ZoneId zoneId)
      Allows to specify the zoneId that will be used to create the recurringJobs. If no zoneId is set, the ZoneId.systemDefault() is used.
      Parameters:
      zoneId - the zoneId that will be used to create the recurringJobs.
      Returns:
      the same builder instance which provides a fluent api
    • build

      protected RecurringJob build(JobDetailsGenerator jobDetailsGenerator)
      Not publicly visible as it will be used by the JobScheduler only.
      Returns:
      the actual Job to create
    • build

      protected RecurringJob build()
      Not publicly visible as it will be used by the JobRequestScheduler only.
      Returns:
      the actual RecurringJob to create