Class JobSchedule

java.lang.Object
io.dapr.client.domain.JobSchedule

public class JobSchedule extends Object
Represents a job schedule using cron expressions or fixed intervals. This class provides various static methods to create schedules based on predefined periods (e.g., daily, weekly, monthly) or using custom cron expressions. Example usage:
 JobsSchedule schedule = JobsSchedule.daily();
 System.out.println(schedule.getExpression()); // Outputs: "0 0 0 * * *"
 
  • Method Details

    • fromPeriod

      public static JobSchedule fromPeriod(Duration duration)
      Creates a job schedule from a fixed period using a Duration. The resulting expression follows the format: "@every XhYmZsWms" where X, Y, Z, and W represent hours, minutes, seconds, and milliseconds respectively. Example:
       JobsSchedule schedule = JobsSchedule.fromPeriod(Duration.ofMinutes(30));
       System.out.println(schedule.getExpression()); // Outputs: "@every 0h30m0s0ms"
       
      Parameters:
      duration - the duration of the period.
      Returns:
      a JobsSchedule with the corresponding interval.
      Throws:
      IllegalArgumentException - if the duration is null.
    • fromString

      public static JobSchedule fromString(String cronExpression)
      Creates a job schedule from a custom cron expression.
      Parameters:
      cronExpression - the cron expression.
      Returns:
      a JobsSchedule representing the given cron expression.
    • yearly

      public static JobSchedule yearly()
      Creates a yearly job schedule, running at midnight on January 1st.
      Returns:
      a JobsSchedule for yearly execution.
    • monthly

      public static JobSchedule monthly()
      Creates a monthly job schedule, running at midnight on the first day of each month.
      Returns:
      a JobsSchedule for monthly execution.
    • weekly

      public static JobSchedule weekly()
      Creates a weekly job schedule, running at midnight on Sunday.
      Returns:
      a JobsSchedule for weekly execution.
    • daily

      public static JobSchedule daily()
      Creates a daily job schedule, running at midnight every day.
      Returns:
      a JobsSchedule for daily execution.
    • hourly

      public static JobSchedule hourly()
      Creates an hourly job schedule, running at the start of every hour.
      Returns:
      a JobsSchedule for hourly execution.
    • getExpression

      public String getExpression()
      Gets the cron expression representing this job schedule.
      Returns:
      the cron expression as a string.