Package io.dapr.client.domain
Class JobSchedule
java.lang.Object
io.dapr.client.domain.JobSchedule
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 Summary
Modifier and TypeMethodDescriptionstatic JobScheduledaily()Creates a daily job schedule, running at midnight every day.static JobSchedulefromPeriod(Duration duration) Creates a job schedule from a fixed period using aDuration.static JobSchedulefromString(String cronExpression) Creates a job schedule from a custom cron expression.Gets the cron expression representing this job schedule.static JobSchedulehourly()Creates an hourly job schedule, running at the start of every hour.static JobSchedulemonthly()Creates a monthly job schedule, running at midnight on the first day of each month.static JobScheduleweekly()Creates a weekly job schedule, running at midnight on Sunday.static JobScheduleyearly()Creates a yearly job schedule, running at midnight on January 1st.
-
Method Details
-
fromPeriod
Creates a job schedule from a fixed period using aDuration. 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
JobsSchedulewith the corresponding interval. - Throws:
IllegalArgumentException- if the duration is null.
-
fromString
Creates a job schedule from a custom cron expression.- Parameters:
cronExpression- the cron expression.- Returns:
- a
JobsSchedulerepresenting the given cron expression.
-
yearly
Creates a yearly job schedule, running at midnight on January 1st.- Returns:
- a
JobsSchedulefor yearly execution.
-
monthly
Creates a monthly job schedule, running at midnight on the first day of each month.- Returns:
- a
JobsSchedulefor monthly execution.
-
weekly
Creates a weekly job schedule, running at midnight on Sunday.- Returns:
- a
JobsSchedulefor weekly execution.
-
daily
Creates a daily job schedule, running at midnight every day.- Returns:
- a
JobsSchedulefor daily execution.
-
hourly
Creates an hourly job schedule, running at the start of every hour.- Returns:
- a
JobsSchedulefor hourly execution.
-
getExpression
Gets the cron expression representing this job schedule.- Returns:
- the cron expression as a string.
-