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

temporalio / sdk-java / #201

16 Oct 2023 03:47PM UTC coverage: 77.389% (+0.02%) from 77.368%
#201

push

github-actions

web-flow
Apply data converter context in more places (#1896)

Add data converter context to memo, lastFailure and schedules

23 of 23 new or added lines in 5 files covered. (100.0%)

18718 of 24187 relevant lines covered (77.39%)

0.77 hits per line

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

1.42
/temporal-sdk/src/main/java/io/temporal/internal/client/ScheduleProtoUtil.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.internal.client;
22

23
import static io.temporal.internal.common.HeaderUtils.toHeaderGrpc;
24

25
import com.google.common.base.MoreObjects;
26
import com.google.common.base.Preconditions;
27
import io.temporal.api.common.v1.*;
28
import io.temporal.api.schedule.v1.*;
29
import io.temporal.api.schedule.v1.Schedule;
30
import io.temporal.api.schedule.v1.ScheduleAction;
31
import io.temporal.api.schedule.v1.ScheduleActionResult;
32
import io.temporal.api.schedule.v1.ScheduleInfo;
33
import io.temporal.api.schedule.v1.ScheduleSpec;
34
import io.temporal.api.schedule.v1.ScheduleState;
35
import io.temporal.api.taskqueue.v1.TaskQueue;
36
import io.temporal.api.workflow.v1.NewWorkflowExecutionInfo;
37
import io.temporal.client.WorkflowOptions;
38
import io.temporal.client.schedules.*;
39
import io.temporal.common.context.ContextPropagator;
40
import io.temporal.common.converter.DataConverter;
41
import io.temporal.common.converter.EncodedValues;
42
import io.temporal.internal.client.external.GenericWorkflowClient;
43
import io.temporal.internal.common.ProtobufTimeUtils;
44
import io.temporal.internal.common.RetryOptionsUtils;
45
import io.temporal.internal.common.SearchAttributesUtil;
46
import io.temporal.payload.context.WorkflowSerializationContext;
47
import java.time.Instant;
48
import java.util.*;
49
import java.util.stream.Collectors;
50
import javax.annotation.Nonnull;
51
import javax.annotation.Nullable;
52

53
public class ScheduleProtoUtil {
54

55
  private final GenericWorkflowClient genericClient;
56
  private final ScheduleClientOptions clientOptions;
57

58
  public ScheduleProtoUtil(
59
      GenericWorkflowClient genericClient, ScheduleClientOptions clientOptions) {
1✔
60
    this.genericClient = genericClient;
1✔
61
    this.clientOptions = clientOptions;
1✔
62
  }
1✔
63

64
  private io.temporal.common.interceptors.Header extractContextsAndConvertToBytes(
65
      List<ContextPropagator> scheduleOptionsContextPropagators) {
66
    List<ContextPropagator> scheduleClientContextPropagators =
×
67
        clientOptions.getContextPropagators();
×
68
    if ((scheduleClientContextPropagators.isEmpty() && scheduleOptionsContextPropagators == null)
×
69
        || (scheduleOptionsContextPropagators != null
70
            && scheduleOptionsContextPropagators.isEmpty())) {
×
71
      return null;
×
72
    }
73

74
    List<ContextPropagator> listToUse =
×
75
        MoreObjects.firstNonNull(
×
76
            scheduleOptionsContextPropagators, scheduleClientContextPropagators);
77
    Map<String, Payload> result = new HashMap<>();
×
78
    for (ContextPropagator propagator : listToUse) {
×
79
      result.putAll(propagator.serializeContext(propagator.getCurrentContext()));
×
80
    }
×
81
    return new io.temporal.common.interceptors.Header(result);
×
82
  }
83

84
  public ScheduleAction actionToProto(io.temporal.client.schedules.ScheduleAction action) {
85
    if (action instanceof ScheduleActionStartWorkflow) {
×
86
      ScheduleActionStartWorkflow startWorkflowAction = (ScheduleActionStartWorkflow) action;
×
87
      DataConverter dataConverterWithWorkflowContext =
×
88
          clientOptions
89
              .getDataConverter()
×
90
              .withContext(
×
91
                  new WorkflowSerializationContext(
92
                      clientOptions.getNamespace(),
×
93
                      startWorkflowAction.getOptions().getWorkflowId()));
×
94

95
      WorkflowOptions wfOptions = startWorkflowAction.getOptions();
×
96
      // Disallow some options
97
      if (wfOptions.getWorkflowIdReusePolicy() != null) {
×
98
        throw new IllegalArgumentException(
×
99
            "ID reuse policy cannot change from default for scheduled workflow");
100
      }
101
      if (wfOptions.getCronSchedule() != null) {
×
102
        throw new IllegalArgumentException("Cron schedule cannot be set on scheduled workflow");
×
103
      }
104
      // Validate required options
105
      if (wfOptions.getWorkflowId() == null || wfOptions.getWorkflowId().isEmpty()) {
×
106
        throw new IllegalArgumentException("ID required on workflow action");
×
107
      }
108
      if (wfOptions.getTaskQueue() == null || wfOptions.getTaskQueue().isEmpty()) {
×
109
        throw new IllegalArgumentException("Task queue required on workflow action");
×
110
      }
111

112
      NewWorkflowExecutionInfo.Builder workflowRequest =
113
          NewWorkflowExecutionInfo.newBuilder()
×
114
              .setWorkflowId(wfOptions.getWorkflowId())
×
115
              .setWorkflowType(
×
116
                  WorkflowType.newBuilder().setName(startWorkflowAction.getWorkflowType()).build())
×
117
              .setWorkflowRunTimeout(
×
118
                  ProtobufTimeUtils.toProtoDuration(wfOptions.getWorkflowRunTimeout()))
×
119
              .setWorkflowExecutionTimeout(
×
120
                  ProtobufTimeUtils.toProtoDuration(wfOptions.getWorkflowExecutionTimeout()))
×
121
              .setWorkflowTaskTimeout(
×
122
                  ProtobufTimeUtils.toProtoDuration(wfOptions.getWorkflowTaskTimeout()))
×
123
              .setTaskQueue(TaskQueue.newBuilder().setName(wfOptions.getTaskQueue()).build());
×
124

125
      startWorkflowAction.getArguments().setDataConverter(dataConverterWithWorkflowContext);
×
126
      Optional<Payloads> inputArgs = startWorkflowAction.getArguments().toPayloads();
×
127
      if (inputArgs.isPresent()) {
×
128
        workflowRequest.setInput(inputArgs.get());
×
129
      }
130

131
      if (startWorkflowAction.getOptions().getMemo() != null) {
×
132
        Map<String, Payload> memo = new HashMap<>();
×
133
        for (Map.Entry<String, Object> item :
134
            startWorkflowAction.getOptions().getMemo().entrySet()) {
×
135
          if (item.getValue() instanceof EncodedValues) {
×
136
            memo.put(
×
137
                item.getKey(), ((EncodedValues) item.getValue()).toPayloads().get().getPayloads(0));
×
138
          } else {
139
            memo.put(
×
140
                item.getKey(), dataConverterWithWorkflowContext.toPayload(item.getValue()).get());
×
141
          }
142
        }
×
143
        workflowRequest.setMemo(Memo.newBuilder().putAllFields(memo).build());
×
144
      }
145

146
      if (wfOptions.getTypedSearchAttributes() != null
×
147
          && wfOptions.getTypedSearchAttributes().size() > 0) {
×
148
        workflowRequest.setSearchAttributes(
×
149
            SearchAttributesUtil.encodeTyped(wfOptions.getTypedSearchAttributes()));
×
150
      }
151

152
      Header grpcHeader =
×
153
          toHeaderGrpc(
×
154
              startWorkflowAction.getHeader(),
×
155
              extractContextsAndConvertToBytes(wfOptions.getContextPropagators()));
×
156
      workflowRequest.setHeader(grpcHeader);
×
157

158
      return ScheduleAction.newBuilder().setStartWorkflow(workflowRequest.build()).build();
×
159
    }
160
    throw new IllegalArgumentException("Unsupported action " + action.getClass());
×
161
  }
162

163
  public SchedulePolicies policyToProto(SchedulePolicy policy) {
164
    return SchedulePolicies.newBuilder()
×
165
        .setCatchupWindow(ProtobufTimeUtils.toProtoDuration(policy.getCatchupWindow()))
×
166
        .setPauseOnFailure(policy.isPauseOnFailure())
×
167
        .setOverlapPolicy(policy.getOverlap())
×
168
        .build();
×
169
  }
170

171
  public List<Range> scheduleRangeToProto(List<ScheduleRange> scheduleRanges) {
172
    ArrayList<Range> ranges = new ArrayList<Range>(scheduleRanges.size());
×
173
    for (ScheduleRange scheduleRange : scheduleRanges) {
×
174
      ranges.add(
×
175
          Range.newBuilder()
×
176
              .setStart(scheduleRange.getStart())
×
177
              .setEnd(scheduleRange.getEnd())
×
178
              .setStep(scheduleRange.getStep())
×
179
              .build());
×
180
    }
×
181
    return ranges;
×
182
  }
183

184
  public ScheduleSpec specToProto(io.temporal.client.schedules.ScheduleSpec spec) {
185
    ScheduleSpec.Builder builder = ScheduleSpec.newBuilder();
×
186

187
    if (spec.getTimeZoneName() != null && !spec.getTimeZoneName().isEmpty()) {
×
188
      builder.setTimezoneName(spec.getTimeZoneName());
×
189
    }
190

191
    if (spec.getJitter() != null) {
×
192
      builder.setJitter(ProtobufTimeUtils.toProtoDuration(spec.getJitter()));
×
193
    }
194

195
    if (spec.getStartAt() != null) {
×
196
      builder.setStartTime(ProtobufTimeUtils.toProtoTimestamp(spec.getStartAt()));
×
197
    }
198

199
    if (spec.getEndAt() != null) {
×
200
      builder.setEndTime(ProtobufTimeUtils.toProtoTimestamp(spec.getEndAt()));
×
201
    }
202

203
    if (spec.getCalendars() != null && !spec.getCalendars().isEmpty()) {
×
204
      for (ScheduleCalendarSpec calendarSpec : spec.getCalendars()) {
×
205
        builder.addStructuredCalendar(
×
206
            StructuredCalendarSpec.newBuilder()
×
207
                .addAllSecond(this.scheduleRangeToProto(calendarSpec.getSeconds()))
×
208
                .addAllMinute(this.scheduleRangeToProto(calendarSpec.getMinutes()))
×
209
                .addAllHour(this.scheduleRangeToProto(calendarSpec.getHour()))
×
210
                .addAllDayOfMonth(this.scheduleRangeToProto(calendarSpec.getDayOfMonth()))
×
211
                .addAllMonth(this.scheduleRangeToProto(calendarSpec.getMonth()))
×
212
                .addAllYear(this.scheduleRangeToProto(calendarSpec.getYear()))
×
213
                .addAllDayOfWeek(this.scheduleRangeToProto(calendarSpec.getDayOfWeek()))
×
214
                .setComment(calendarSpec.getComment())
×
215
                .build());
×
216
      }
×
217
    }
218

219
    if (spec.getIntervals() != null && !spec.getIntervals().isEmpty()) {
×
220
      for (ScheduleIntervalSpec intervalSpec : spec.getIntervals()) {
×
221
        builder.addInterval(
×
222
            IntervalSpec.newBuilder()
×
223
                .setInterval(ProtobufTimeUtils.toProtoDuration(intervalSpec.getEvery()))
×
224
                .setPhase(ProtobufTimeUtils.toProtoDuration(intervalSpec.getOffset()))
×
225
                .build());
×
226
      }
×
227
    }
228

229
    if (spec.getCronExpressions() != null && !spec.getCronExpressions().isEmpty()) {
×
230
      builder.addAllCronString(spec.getCronExpressions());
×
231
    }
232

233
    if (spec.getSkip() != null && !spec.getSkip().isEmpty()) {
×
234
      for (ScheduleCalendarSpec calendarSpec : spec.getSkip()) {
×
235
        builder.addExcludeStructuredCalendar(
×
236
            StructuredCalendarSpec.newBuilder()
×
237
                .addAllSecond(this.scheduleRangeToProto(calendarSpec.getSeconds()))
×
238
                .addAllMinute(this.scheduleRangeToProto(calendarSpec.getMinutes()))
×
239
                .addAllHour(this.scheduleRangeToProto(calendarSpec.getHour()))
×
240
                .addAllDayOfMonth(this.scheduleRangeToProto(calendarSpec.getDayOfMonth()))
×
241
                .addAllMonth(this.scheduleRangeToProto(calendarSpec.getMonth()))
×
242
                .addAllYear(this.scheduleRangeToProto(calendarSpec.getYear()))
×
243
                .addAllDayOfWeek(this.scheduleRangeToProto(calendarSpec.getDayOfWeek()))
×
244
                .setComment(calendarSpec.getComment())
×
245
                .build());
×
246
      }
×
247
    }
248

249
    return builder.build();
×
250
  }
251

252
  public @Nonnull Schedule scheduleToProto(
253
      @Nonnull io.temporal.client.schedules.Schedule schedule) {
254
    Preconditions.checkNotNull(schedule);
×
255

256
    Schedule.Builder scheduleBuilder =
257
        Schedule.newBuilder()
×
258
            .setAction(this.actionToProto(schedule.getAction()))
×
259
            .setSpec(this.specToProto(schedule.getSpec()));
×
260

261
    if (schedule.getPolicy() != null) {
×
262
      scheduleBuilder.setPolicies(this.policyToProto(schedule.getPolicy()));
×
263
    }
264

265
    if (schedule.getState() != null) {
×
266
      scheduleBuilder.setState(this.stateToProto(schedule.getState()));
×
267
    }
268

269
    return scheduleBuilder.build();
×
270
  }
271

272
  public ScheduleState stateToProto(io.temporal.client.schedules.ScheduleState state) {
273
    ScheduleState.Builder stateBuilder =
274
        ScheduleState.newBuilder()
×
275
            .setLimitedActions(state.isLimitedAction())
×
276
            .setRemainingActions(state.getRemainingActions())
×
277
            .setPaused(state.isPaused());
×
278
    if (state.getNote() != null) {
×
279
      stateBuilder.setNotes(state.getNote());
×
280
    }
281
    return stateBuilder.build();
×
282
  }
283

284
  public ScheduleRange protoToScheduleRange(Range protoRange) {
285
    return new ScheduleRange(protoRange.getStart(), protoRange.getEnd(), protoRange.getStep());
×
286
  }
287

288
  public ScheduleIntervalSpec protoToScheduleInterval(IntervalSpec protoInterval) {
289
    return new ScheduleIntervalSpec(
×
290
        ProtobufTimeUtils.toJavaDuration(protoInterval.getInterval()),
×
291
        ProtobufTimeUtils.toJavaDuration(protoInterval.getPhase()));
×
292
  }
293

294
  public List<ScheduleRange> protoToScheduleRanges(List<Range> protoRanges) {
295
    return protoRanges.stream().map(t -> this.protoToScheduleRange(t)).collect(Collectors.toList());
×
296
  }
297

298
  public ScheduleCalendarSpec protoToScheduleCalendar(StructuredCalendarSpec protoSpec) {
299
    ScheduleCalendarSpec.Builder calendarBuilder =
300
        ScheduleCalendarSpec.newBuilder()
×
301
            .setComment(protoSpec.getComment())
×
302
            .setSeconds(protoToScheduleRanges(protoSpec.getSecondList()))
×
303
            .setMinutes(protoToScheduleRanges(protoSpec.getMinuteList()))
×
304
            .setHour(protoToScheduleRanges(protoSpec.getHourList()))
×
305
            .setDayOfMonth(protoToScheduleRanges(protoSpec.getDayOfMonthList()))
×
306
            .setMonth(protoToScheduleRanges(protoSpec.getMonthList()))
×
307
            .setYear(protoToScheduleRanges(protoSpec.getYearList()))
×
308
            .setDayOfWeek(protoToScheduleRanges(protoSpec.getDayOfWeekList()));
×
309

310
    return calendarBuilder.build();
×
311
  }
312

313
  @Nonnull
314
  public io.temporal.client.schedules.ScheduleSpec protoToScheduleSpec(
315
      @Nonnull ScheduleSpec scheduleSpec) {
316
    Objects.requireNonNull(scheduleSpec);
×
317
    io.temporal.client.schedules.ScheduleSpec.Builder specBuilder =
318
        io.temporal.client.schedules.ScheduleSpec.newBuilder()
×
319
            .setTimeZoneName(
×
320
                scheduleSpec.getTimezoneName() == null ? "" : scheduleSpec.getTimezoneName());
×
321

322
    if (scheduleSpec.hasJitter()) {
×
323
      specBuilder.setJitter(ProtobufTimeUtils.toJavaDuration(scheduleSpec.getJitter()));
×
324
    }
325

326
    if (scheduleSpec.hasStartTime()) {
×
327
      specBuilder.setStartAt(ProtobufTimeUtils.toJavaInstant(scheduleSpec.getStartTime()));
×
328
    }
329

330
    if (scheduleSpec.hasEndTime()) {
×
331
      specBuilder.setEndAt(ProtobufTimeUtils.toJavaInstant(scheduleSpec.getEndTime()));
×
332
    }
333

334
    specBuilder.setCalendars(
×
335
        scheduleSpec.getStructuredCalendarList().stream()
×
336
            .map(c -> this.protoToScheduleCalendar(c))
×
337
            .collect(Collectors.toList()));
×
338

339
    specBuilder.setCronExpressions(scheduleSpec.getCronStringList());
×
340

341
    specBuilder.setIntervals(
×
342
        scheduleSpec.getIntervalList().stream()
×
343
            .map(i -> this.protoToScheduleInterval(i))
×
344
            .collect(Collectors.toList()));
×
345

346
    specBuilder.setSkip(
×
347
        scheduleSpec.getExcludeStructuredCalendarList().stream()
×
348
            .map(c -> this.protoToScheduleCalendar(c))
×
349
            .collect(Collectors.toList()));
×
350

351
    return specBuilder.build();
×
352
  }
353

354
  public List<io.temporal.client.schedules.ScheduleActionResult> protoToActionResults(
355
      List<ScheduleActionResult> results) {
356
    return results.stream()
×
357
        .map(
×
358
            a ->
359
                new io.temporal.client.schedules.ScheduleActionResult(
×
360
                    ProtobufTimeUtils.toJavaInstant(a.getScheduleTime()),
×
361
                    ProtobufTimeUtils.toJavaInstant(a.getActualTime()),
×
362
                    new ScheduleActionExecutionStartWorkflow(
363
                        a.getStartWorkflowResult().getWorkflowId(),
×
364
                        a.getStartWorkflowResult().getRunId())))
×
365
        .collect(Collectors.toList());
×
366
  }
367

368
  public ScheduleListDescription protoToScheduleListDescription(ScheduleListEntry entry) {
369
    List<Instant> nextActionTimes =
×
370
        entry.getInfo().getFutureActionTimesList().stream()
×
371
            .map(ProtobufTimeUtils::toJavaInstant)
×
372
            .collect(Collectors.toList());
×
373

374
    io.temporal.client.schedules.ScheduleListInfo info =
×
375
        new io.temporal.client.schedules.ScheduleListInfo(
376
            this.protoToActionResults(entry.getInfo().getRecentActionsList()), nextActionTimes);
×
377

378
    ScheduleListActionStartWorkflow action =
×
379
        new ScheduleListActionStartWorkflow(entry.getInfo().getWorkflowType().getName());
×
380

381
    ScheduleListState state =
×
382
        new ScheduleListState(entry.getInfo().getNotes(), entry.getInfo().getPaused());
×
383

384
    io.temporal.client.schedules.ScheduleSpec spec = protoToScheduleSpec(entry.getInfo().getSpec());
×
385

386
    return new ScheduleListDescription(
×
387
        entry.getScheduleId(),
×
388
        new ScheduleListSchedule(action, spec, state),
389
        info,
390
        entry.getMemo().getFieldsMap(),
×
391
        this.clientOptions.getDataConverter(),
×
392
        Collections.unmodifiableMap(SearchAttributesUtil.decode(entry.getSearchAttributes())));
×
393
  }
394

395
  @Nonnull
396
  public io.temporal.client.schedules.ScheduleAction protoToAction(@Nonnull ScheduleAction action) {
397
    Objects.requireNonNull(action);
×
398
    if (action.hasStartWorkflow()) {
×
399
      NewWorkflowExecutionInfo startWfAction = action.getStartWorkflow();
×
400
      DataConverter dataConverterWithWorkflowContext =
×
401
          clientOptions
402
              .getDataConverter()
×
403
              .withContext(
×
404
                  new WorkflowSerializationContext(
405
                      clientOptions.getNamespace(), startWfAction.getWorkflowId()));
×
406

407
      ScheduleActionStartWorkflow.Builder builder = ScheduleActionStartWorkflow.newBuilder();
×
408
      builder.setWorkflowType(startWfAction.getWorkflowType().getName());
×
409

410
      builder.setRawArguments(
×
411
          new EncodedValues(
412
              Optional.of(startWfAction.getInput()), dataConverterWithWorkflowContext));
×
413

414
      WorkflowOptions.Builder wfOptionsBuilder = WorkflowOptions.newBuilder();
×
415
      // set required options
416
      wfOptionsBuilder.setWorkflowId(startWfAction.getWorkflowId());
×
417
      wfOptionsBuilder.setTaskQueue(startWfAction.getTaskQueue().getName());
×
418
      // set timeouts
419
      wfOptionsBuilder.setWorkflowExecutionTimeout(
×
420
          ProtobufTimeUtils.toJavaDuration(startWfAction.getWorkflowExecutionTimeout()));
×
421

422
      wfOptionsBuilder.setWorkflowRunTimeout(
×
423
          ProtobufTimeUtils.toJavaDuration(startWfAction.getWorkflowRunTimeout()));
×
424

425
      wfOptionsBuilder.setWorkflowTaskTimeout(
×
426
          ProtobufTimeUtils.toJavaDuration(startWfAction.getWorkflowTaskTimeout()));
×
427

428
      if (startWfAction.getRetryPolicy() != null) {
×
429
        wfOptionsBuilder.setRetryOptions(
×
430
            RetryOptionsUtils.toRetryOptions(startWfAction.getRetryPolicy()));
×
431
      }
432

433
      if (startWfAction.hasMemo()) {
×
434
        Map<String, Object> memos = new HashMap<>();
×
435
        for (Map.Entry<String, Payload> memo : startWfAction.getMemo().getFieldsMap().entrySet()) {
×
436
          EncodedValues encodedMemo =
×
437
              new EncodedValues(
438
                  Optional.of(Payloads.newBuilder().addPayloads(memo.getValue()).build()),
×
439
                  dataConverterWithWorkflowContext);
440
          memos.put(memo.getKey(), encodedMemo);
×
441
        }
×
442
        wfOptionsBuilder.setMemo(memos);
×
443
      }
444

445
      if (startWfAction.hasSearchAttributes()) {
×
446
        wfOptionsBuilder.setTypedSearchAttributes(
×
447
            SearchAttributesUtil.decodeTyped(startWfAction.getSearchAttributes()));
×
448
      }
449

450
      builder.setOptions(wfOptionsBuilder.build());
×
451
      return builder.build();
×
452
    }
453
    throw new IllegalArgumentException("Unsupported action " + action.getActionCase());
×
454
  }
455

456
  @Nullable
457
  public SchedulePolicy protoToPolicy(@Nullable SchedulePolicies policy) {
458
    if (policy == null) {
×
459
      return null;
×
460
    }
461
    SchedulePolicy.Builder policyBuilder =
462
        SchedulePolicy.newBuilder()
×
463
            .setPauseOnFailure(policy.getPauseOnFailure())
×
464
            .setOverlap(policy.getOverlapPolicy());
×
465
    if (policy.hasCatchupWindow()) {
×
466
      policyBuilder.setCatchupWindow(ProtobufTimeUtils.toJavaDuration(policy.getCatchupWindow()));
×
467
    }
468
    return policyBuilder.build();
×
469
  }
470

471
  @Nullable
472
  public io.temporal.client.schedules.ScheduleState protoToScheduleState(
473
      @Nullable ScheduleState state) {
474
    if (state == null) {
×
475
      return null;
×
476
    }
477
    return io.temporal.client.schedules.ScheduleState.newBuilder()
×
478
        .setNote(state.getNotes())
×
479
        .setPaused(state.getPaused())
×
480
        .setRemainingActions(state.getRemainingActions())
×
481
        .setLimitedAction(state.getLimitedActions())
×
482
        .build();
×
483
  }
484

485
  public io.temporal.client.schedules.Schedule protoToSchedule(Schedule schedule) {
486
    return io.temporal.client.schedules.Schedule.newBuilder()
×
487
        .setAction(protoToAction(schedule.getAction()))
×
488
        .setSpec(protoToScheduleSpec(schedule.getSpec()))
×
489
        .setPolicy(protoToPolicy(schedule.getPolicies()))
×
490
        .setState(protoToScheduleState(schedule.getState()))
×
491
        .build();
×
492
  }
493

494
  public io.temporal.client.schedules.ScheduleInfo protoToScheduleInfo(ScheduleInfo info) {
495
    return new io.temporal.client.schedules.ScheduleInfo(
×
496
        info.getActionCount(),
×
497
        info.getMissedCatchupWindow(),
×
498
        info.getOverlapSkipped(),
×
499
        info.getRunningWorkflowsList().stream()
×
500
            .map(wf -> new ScheduleActionExecutionStartWorkflow(wf.getWorkflowId(), wf.getRunId()))
×
501
            .collect(Collectors.toList()),
×
502
        this.protoToActionResults(info.getRecentActionsList()),
×
503
        info.getFutureActionTimesList().stream()
×
504
            .map(t -> ProtobufTimeUtils.toJavaInstant(t))
×
505
            .collect(Collectors.toList()),
×
506
        info.hasCreateTime() ? ProtobufTimeUtils.toJavaInstant(info.getCreateTime()) : null,
×
507
        info.hasUpdateTime() ? ProtobufTimeUtils.toJavaInstant(info.getUpdateTime()) : null);
×
508
  }
509
}
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