• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

temporalio / sdk-java / #174

pending completion
#174

push

github-actions

web-flow
Add schedules API (#1776)

Add schedules API

1143 of 1143 new or added lines in 35 files covered. (100.0%)

18101 of 23284 relevant lines covered (77.74%)

0.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/temporal-sdk/src/main/java/io/temporal/client/schedules/ScheduleSpec.java
1
/*
2
 * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3
 *
4
 * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
 *
6
 * Modifications copyright (C) 2017 Uber Technologies, Inc.
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this material except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20

21
package io.temporal.client.schedules;
22

23
import java.time.Duration;
24
import java.time.Instant;
25
import java.util.List;
26
import java.util.Objects;
27

28
/**
29
 * Specification of the times scheduled actions may occur. The times are the union of {@link
30
 * ScheduleSpec#calendars}, {@link ScheduleSpec#intervals}, and {@link ScheduleSpec#cronExpressions}
31
 * excluding anything in {@link ScheduleSpec#skip}.
32
 */
33
public final class ScheduleSpec {
34
  public static ScheduleSpec.Builder newBuilder() {
35
    return new ScheduleSpec.Builder();
×
36
  }
37

38
  public static ScheduleSpec.Builder newBuilder(ScheduleSpec options) {
39
    return new ScheduleSpec.Builder(options);
×
40
  }
41

42
  public static final class Builder {
43
    private List<ScheduleCalendarSpec> calendars;
44
    private List<ScheduleIntervalSpec> intervals;
45
    private List<String> cronExpressions;
46
    private List<ScheduleCalendarSpec> skip;
47
    private Instant startAt;
48
    private Instant endAt;
49
    private Duration jitter;
50
    private String timeZoneName;
51

52
    private Builder() {}
53

54
    private Builder(ScheduleSpec options) {
×
55
      if (options == null) {
×
56
        return;
×
57
      }
58
      this.calendars = options.calendars;
×
59
      this.intervals = options.intervals;
×
60
      this.cronExpressions = options.cronExpressions;
×
61
      this.skip = options.skip;
×
62
      this.startAt = options.startAt;
×
63
      this.endAt = options.endAt;
×
64
      this.jitter = options.jitter;
×
65
      this.timeZoneName = options.timeZoneName;
×
66
    }
×
67

68
    /** Set the calendar-based specification of times a schedule should run. */
69
    public Builder setCalendars(List<ScheduleCalendarSpec> calendars) {
70
      this.calendars = calendars;
×
71
      return this;
×
72
    }
73

74
    /** Set the interval-based specification of times a schedule should run. */
75
    public Builder setIntervals(List<ScheduleIntervalSpec> intervals) {
76
      this.intervals = intervals;
×
77
      return this;
×
78
    }
79

80
    /**
81
     * Set the cron-based specification of times a schedule should run.
82
     *
83
     * <p>This is provided for easy migration from legacy string-based cron scheduling. New uses
84
     * should use {@link ScheduleSpec#calendars} instead. These expressions will be translated to
85
     * calendar-based specifications on the server.
86
     */
87
    public Builder setCronExpressions(List<String> cronExpressions) {
88
      this.cronExpressions = cronExpressions;
×
89
      return this;
×
90
    }
91

92
    /** Set the calendar-based specification of times a schedule should not run. */
93
    public Builder setSkip(List<ScheduleCalendarSpec> skip) {
94
      this.skip = skip;
×
95
      return this;
×
96
    }
97

98
    /** Set the start time of the schedule, before which any matching times will be skipped. */
99
    public Builder setStartAt(Instant startAt) {
100
      this.startAt = startAt;
×
101
      return this;
×
102
    }
103

104
    /** Set the end time of the schedule, after which any matching times will be skipped. */
105
    public Builder setEndAt(Instant endAt) {
106
      this.endAt = endAt;
×
107
      return this;
×
108
    }
109

110
    /**
111
     * Set the jitter to apply to each action.
112
     *
113
     * <p>An action's schedule time will be incremented by a random value between 0 and this value
114
     * if present (but not past the next schedule).
115
     */
116
    public Builder setJitter(Duration jitter) {
117
      this.jitter = jitter;
×
118
      return this;
×
119
    }
120

121
    /** Set the schedules time zone as a string, for example <c>US/Central</c>. */
122
    public Builder setTimeZoneName(String timeZoneName) {
123
      this.timeZoneName = timeZoneName;
×
124
      return this;
×
125
    }
126

127
    public ScheduleSpec build() {
128
      return new ScheduleSpec(
×
129
          calendars, intervals, cronExpressions, skip, startAt, endAt, jitter, timeZoneName);
130
    }
131
  }
132

133
  private final List<ScheduleCalendarSpec> calendars;
134
  private final List<ScheduleIntervalSpec> intervals;
135
  private final List<String> cronExpressions;
136
  private final List<ScheduleCalendarSpec> skip;
137
  private final Instant startAt;
138
  private final Instant endAt;
139
  private final Duration jitter;
140
  private final String timeZoneName;
141

142
  private ScheduleSpec(
143
      List<ScheduleCalendarSpec> calendars,
144
      List<ScheduleIntervalSpec> intervals,
145
      List<String> cronExpressions,
146
      List<ScheduleCalendarSpec> skip,
147
      Instant startAt,
148
      Instant endAt,
149
      Duration jitter,
150
      String timeZoneName) {
×
151
    this.calendars = calendars;
×
152
    this.intervals = intervals;
×
153
    this.cronExpressions = cronExpressions;
×
154
    this.skip = skip;
×
155
    this.startAt = startAt;
×
156
    this.endAt = endAt;
×
157
    this.jitter = jitter;
×
158
    this.timeZoneName = timeZoneName;
×
159
  }
×
160

161
  /**
162
   * Gets the calendar-based specification of times.
163
   *
164
   * @return list of {@link ScheduleCalendarSpec} the schedule may run at.
165
   */
166
  public List<ScheduleCalendarSpec> getCalendars() {
167
    return calendars;
×
168
  }
169

170
  /**
171
   * Gets the interval-based specification of times.
172
   *
173
   * @return list of {@link ScheduleIntervalSpec} the schedule may run at.
174
   */
175
  public List<ScheduleIntervalSpec> getIntervals() {
176
    return intervals;
×
177
  }
178

179
  /**
180
   * Gets the cron-based specification of times.
181
   *
182
   * <p>This is provided for easy migration from legacy string-based cron scheduling. New uses
183
   * should use {@link ScheduleSpec#calendars} instead. These expressions will be translated to
184
   * calendar-based specifications on the server.
185
   *
186
   * @return list of cron expressions the schedule may run at.
187
   */
188
  public List<String> getCronExpressions() {
189
    return cronExpressions;
×
190
  }
191

192
  /**
193
   * Gets the set of matching calendar times that will be skipped.
194
   *
195
   * @return list of {@link ScheduleCalendarSpec} the schedule will not run at.
196
   */
197
  public List<ScheduleCalendarSpec> getSkip() {
198
    return skip;
×
199
  }
200

201
  /**
202
   * Gets the time before which any matching times will be skipped.
203
   *
204
   * @return schedule start time
205
   */
206
  public Instant getStartAt() {
207
    return startAt;
×
208
  }
209

210
  /**
211
   * Gets the time after which any matching times will be skipped.
212
   *
213
   * @return schedule end time
214
   */
215
  public Instant getEndAt() {
216
    return endAt;
×
217
  }
218

219
  /**
220
   * Gets the jitter to apply to each action.
221
   *
222
   * @return amount of jitter applied
223
   */
224
  public Duration getJitter() {
225
    return jitter;
×
226
  }
227

228
  /**
229
   * Gets the IANA time zone name, for example <c>US/Central</c>.
230
   *
231
   * @return string representing the timezone.
232
   */
233
  public String getTimeZoneName() {
234
    return timeZoneName;
×
235
  }
236

237
  @Override
238
  public boolean equals(Object o) {
239
    if (this == o) return true;
×
240
    if (o == null || getClass() != o.getClass()) return false;
×
241
    ScheduleSpec that = (ScheduleSpec) o;
×
242
    return Objects.equals(calendars, that.calendars)
×
243
        && Objects.equals(intervals, that.intervals)
×
244
        && Objects.equals(cronExpressions, that.cronExpressions)
×
245
        && Objects.equals(skip, that.skip)
×
246
        && Objects.equals(startAt, that.startAt)
×
247
        && Objects.equals(endAt, that.endAt)
×
248
        && Objects.equals(jitter, that.jitter)
×
249
        && Objects.equals(timeZoneName, that.timeZoneName);
×
250
  }
251

252
  @Override
253
  public int hashCode() {
254
    return Objects.hash(
×
255
        calendars, intervals, cronExpressions, skip, startAt, endAt, jitter, timeZoneName);
256
  }
257

258
  @Override
259
  public String toString() {
260
    return "ScheduleSpec{"
×
261
        + "calendars="
262
        + calendars
263
        + ", intervals="
264
        + intervals
265
        + ", cronExpressions="
266
        + cronExpressions
267
        + ", skip="
268
        + skip
269
        + ", startAt="
270
        + startAt
271
        + ", endAt="
272
        + endAt
273
        + ", jitter="
274
        + jitter
275
        + ", timeZoneName='"
276
        + timeZoneName
277
        + '\''
278
        + '}';
279
  }
280
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc