or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

activities.mdclient.mddata-conversion.mdexceptions.mdindex.mdworkers.mdworkflows.md

workflows.mddocs/

0

# Workflow Implementation and Lifecycle

1

2

APIs for implementing workflow logic with deterministic execution, including timers, signals, queries, updates, and child workflows.

3

4

## Capabilities

5

6

### Workflow Utility Class

7

8

Central utility class providing workflow execution context and APIs for activities, timers, signals, etc.

9

10

```java { .api }

11

/**

12

* Central utility class providing workflow execution context and APIs for activities, timers, signals, etc.

13

*/

14

public final class Workflow {

15

/**

16

* Creates activity client stub with default options.

17

* @param activityInterface activity interface class

18

* @return activity stub

19

*/

20

public static <T> T newActivityStub(Class<T> activityInterface);

21

22

/**

23

* Creates activity client stub with options.

24

* @param activityInterface activity interface class

25

* @param options activity options

26

* @return activity stub

27

*/

28

public static <T> T newActivityStub(Class<T> activityInterface, ActivityOptions options);

29

30

/**

31

* Creates local activity stub with options.

32

* @param activityInterface activity interface class

33

* @param options local activity options

34

* @return local activity stub

35

*/

36

public static <T> T newLocalActivityStub(Class<T> activityInterface, LocalActivityOptions options);

37

38

/**

39

* Creates child workflow stub.

40

* @param workflowInterface workflow interface class

41

* @param options child workflow options

42

* @return child workflow stub

43

*/

44

public static <T> T newChildWorkflowStub(Class<T> workflowInterface, ChildWorkflowOptions options);

45

46

/**

47

* Creates external workflow stub for signaling.

48

* @param workflowInterface workflow interface class

49

* @param workflowId target workflow ID

50

* @return external workflow stub

51

*/

52

public static <T> T newExternalWorkflowStub(Class<T> workflowInterface, String workflowId);

53

54

/**

55

* Creates external workflow stub with run ID.

56

* @param workflowInterface workflow interface class

57

* @param workflowExecution target workflow execution

58

* @return external workflow stub

59

*/

60

public static <T> T newExternalWorkflowStub(Class<T> workflowInterface, WorkflowExecution workflowExecution);

61

62

/**

63

* Deterministic sleep/timer.

64

* @param duration sleep duration

65

*/

66

public static void sleep(Duration duration);

67

68

/**

69

* Deterministic current time.

70

* @return current time in milliseconds since epoch

71

*/

72

public static long currentTimeMillis();

73

74

/**

75

* Deterministic random number generator.

76

* @return random instance seeded with workflow execution

77

*/

78

public static Random newRandom();

79

80

/**

81

* Execute side effect that is recorded in workflow history.

82

* @param resultClass result class

83

* @param func side effect function

84

* @return side effect result

85

*/

86

public static <R> R sideEffect(Class<R> resultClass, Func<R> func);

87

88

/**

89

* Execute mutable side effect with change detection.

90

* @param id unique side effect identifier

91

* @param resultClass result class

92

* @param updated function to compare old and new values

93

* @param func side effect function

94

* @return side effect result

95

*/

96

public static <R> R mutableSideEffect(String id, Class<R> resultClass, BiPredicate<R, R> updated, Func<R> func);

97

98

/**

99

* Get workflow version for backwards compatibility.

100

* @param changeId unique change identifier

101

* @param minSupported minimum supported version

102

* @param maxSupported maximum supported version

103

* @return workflow version

104

*/

105

public static int getVersion(String changeId, int minSupported, int maxSupported);

106

107

/**

108

* Continue as new workflow with same type.

109

* @param args new workflow arguments

110

*/

111

public static void continueAsNew(Object... args);

112

113

/**

114

* Continue as new workflow with options.

115

* @param options continue as new options

116

* @param args new workflow arguments

117

*/

118

public static void continueAsNew(ContinueAsNewOptions options, Object... args);

119

120

/**

121

* Create cancellation scope for managing cancellation.

122

* @param detached whether scope is detached from parent

123

* @param runnable code to execute in scope

124

* @return cancellation scope

125

*/

126

public static CancellationScope newCancellationScope(boolean detached, Runnable runnable);

127

128

/**

129

* Create disconnected cancellation scope.

130

* @param runnable code to execute in scope

131

* @return disconnected cancellation scope

132

*/

133

public static CancellationScope newDetachedCancellationScope(Runnable runnable);

134

135

/**

136

* Get current cancellation scope.

137

* @return current cancellation scope

138

*/

139

public static CancellationScope current();

140

141

/**

142

* Returns workflow info for current execution.

143

* @return workflow info

144

*/

145

public static WorkflowInfo getInfo();

146

147

/**

148

* Returns logger for current workflow.

149

* @param clazz logger class

150

* @return logger instance

151

*/

152

public static Logger getLogger(Class<?> clazz);

153

154

/**

155

* Returns logger for current workflow.

156

* @param name logger name

157

* @return logger instance

158

*/

159

public static Logger getLogger(String name);

160

161

/**

162

* Returns metrics scope for workflow metrics.

163

* @return metrics scope

164

*/

165

public static Scope getMetricsScope();

166

167

/**

168

* Get search attributes for current workflow.

169

* @return search attributes

170

*/

171

public static SearchAttributes getSearchAttributes();

172

173

/**

174

* Get typed search attributes for current workflow.

175

* @return typed search attributes

176

*/

177

public static SearchAttributes getTypedSearchAttributes();

178

179

/**

180

* Upsert search attributes for current workflow.

181

* @param searchAttributes search attributes to upsert

182

*/

183

public static void upsertSearchAttributes(Map<String, ?> searchAttributes);

184

185

/**

186

* Upsert typed search attributes for current workflow.

187

* @param searchAttributes typed search attributes to upsert

188

*/

189

public static void upsertTypedSearchAttributes(SearchAttributes searchAttributes);

190

191

/**

192

* Get memo for current workflow.

193

* @return memo map

194

*/

195

public static Map<String, Object> getMemo();

196

197

/**

198

* Register query handler dynamically.

199

* @param queryType query type name

200

* @param queryHandler query handler function

201

*/

202

public static <R> void registerListener(String queryType, Functions.Func<R> queryHandler);

203

204

/**

205

* Register signal handler dynamically.

206

* @param signalType signal type name

207

* @param signalHandler signal handler function

208

*/

209

public static void registerListener(String signalType, Functions.Proc1<Object> signalHandler);

210

211

/**

212

* Register update handler dynamically.

213

* @param updateType update type name

214

* @param updateHandler update handler function

215

*/

216

public static <R> void registerListener(String updateType, Functions.Func1<Object, R> updateHandler);

217

218

/**

219

* Await condition with timeout.

220

* @param timeout maximum wait time

221

* @param condition condition supplier

222

* @return true if condition became true within timeout

223

*/

224

public static boolean await(Duration timeout, Supplier<Boolean> condition);

225

226

/**

227

* Await condition indefinitely.

228

* @param condition condition supplier

229

*/

230

public static void await(Supplier<Boolean> condition);

231

232

/**

233

* Execute promise asynchronously.

234

* @param task async task

235

* @return promise for async execution

236

*/

237

public static <R> Promise<R> async(Functions.Func<R> task);

238

239

/**

240

* Execute procedure asynchronously.

241

* @param task async procedure

242

* @return promise for async execution

243

*/

244

public static Promise<Void> async(Functions.Proc task);

245

246

/**

247

* Create new promise.

248

* @return new promise

249

*/

250

public static <R> Promise<R> newPromise();

251

252

/**

253

* Wait for all promises to complete.

254

* @param promises collection of promises

255

* @return promise that completes when all input promises complete

256

*/

257

public static Promise<Void> allOf(Promise<?>... promises);

258

259

/**

260

* Wait for any promise to complete.

261

* @param promises collection of promises

262

* @return promise that completes when any input promise completes

263

*/

264

public static Promise<Object> anyOf(Promise<?>... promises);

265

}

266

```

267

268

**Usage Examples:**

269

270

```java

271

@WorkflowInterface

272

public interface OrderProcessingWorkflow {

273

@WorkflowMethod

274

OrderResult processOrder(OrderRequest order);

275

276

@SignalMethod

277

void addItem(OrderItem item);

278

279

@QueryMethod

280

OrderStatus getStatus();

281

282

@UpdateMethod

283

void updateShippingAddress(Address newAddress);

284

}

285

286

public class OrderProcessingWorkflowImpl implements OrderProcessingWorkflow {

287

private final OrderActivities activities = Workflow.newActivityStub(

288

OrderActivities.class,

289

ActivityOptions.newBuilder()

290

.setStartToCloseTimeout(Duration.ofMinutes(5))

291

.setRetryOptions(RetryOptions.newBuilder()

292

.setMaximumAttempts(3)

293

.build())

294

.build()

295

);

296

297

private OrderStatus status = OrderStatus.CREATED;

298

private final List<OrderItem> items = new ArrayList<>();

299

private Address shippingAddress;

300

301

@Override

302

public OrderResult processOrder(OrderRequest order) {

303

this.shippingAddress = order.getShippingAddress();

304

this.items.addAll(order.getItems());

305

306

// Validate order

307

status = OrderStatus.VALIDATING;

308

boolean isValid = activities.validateOrder(order);

309

if (!isValid) {

310

status = OrderStatus.REJECTED;

311

return new OrderResult(false, "Order validation failed");

312

}

313

314

// Process payment

315

status = OrderStatus.PROCESSING_PAYMENT;

316

PaymentResult payment = activities.processPayment(order.getPaymentInfo());

317

if (!payment.isSuccessful()) {

318

status = OrderStatus.PAYMENT_FAILED;

319

return new OrderResult(false, "Payment failed: " + payment.getErrorMessage());

320

}

321

322

// Create shipment

323

status = OrderStatus.CREATING_SHIPMENT;

324

ShipmentInfo shipment = activities.createShipment(shippingAddress, items);

325

326

// Send confirmation

327

activities.sendOrderConfirmation(order.getCustomerEmail(), shipment);

328

329

status = OrderStatus.COMPLETED;

330

return new OrderResult(true, shipment.getTrackingNumber());

331

}

332

333

@Override

334

public void addItem(OrderItem item) {

335

if (status == OrderStatus.CREATED) {

336

items.add(item);

337

}

338

}

339

340

@Override

341

public OrderStatus getStatus() {

342

return status;

343

}

344

345

@Override

346

public void updateShippingAddress(Address newAddress) {

347

if (status.ordinal() < OrderStatus.CREATING_SHIPMENT.ordinal()) {

348

this.shippingAddress = newAddress;

349

} else {

350

throw new IllegalStateException("Cannot update address after shipment creation");

351

}

352

}

353

}

354

```

355

356

### Workflow Information

357

358

Information about the current workflow execution.

359

360

```java { .api }

361

/**

362

* Information about the current workflow execution.

363

*/

364

public interface WorkflowInfo {

365

/**

366

* Workflow execution namespace.

367

* @return namespace name

368

*/

369

String getNamespace();

370

371

/**

372

* Workflow ID.

373

* @return workflow ID

374

*/

375

String getWorkflowId();

376

377

/**

378

* Workflow run ID.

379

* @return run ID

380

*/

381

String getRunId();

382

383

/**

384

* Workflow type name.

385

* @return workflow type

386

*/

387

String getWorkflowType();

388

389

/**

390

* Task queue name.

391

* @return task queue

392

*/

393

String getTaskQueue();

394

395

/**

396

* Workflow execution start time.

397

* @return start time in milliseconds since epoch

398

*/

399

long getWorkflowStartTime();

400

401

/**

402

* Workflow execution timeout.

403

* @return execution timeout duration

404

*/

405

Duration getWorkflowExecutionTimeout();

406

407

/**

408

* Workflow run timeout.

409

* @return run timeout duration

410

*/

411

Duration getWorkflowRunTimeout();

412

413

/**

414

* Workflow task timeout.

415

* @return task timeout duration

416

*/

417

Duration getWorkflowTaskTimeout();

418

419

/**

420

* Workflow attempt number.

421

* @return attempt number starting from 1

422

*/

423

int getAttempt();

424

425

/**

426

* Cron schedule if workflow is scheduled.

427

* @return optional cron schedule

428

*/

429

Optional<String> getCronSchedule();

430

431

/**

432

* Continued execution run ID if this is a continued workflow.

433

* @return optional continued run ID

434

*/

435

Optional<String> getContinuedExecutionRunId();

436

437

/**

438

* Parent workflow execution if this is a child workflow.

439

* @return optional parent execution

440

*/

441

Optional<WorkflowExecution> getParentWorkflowExecution();

442

443

/**

444

* Parent namespace if this is a child workflow.

445

* @return optional parent namespace

446

*/

447

Optional<String> getParentNamespace();

448

449

/**

450

* Search attributes for this workflow.

451

* @return search attributes map

452

*/

453

Map<String, Object> getSearchAttributes();

454

455

/**

456

* Typed search attributes for this workflow.

457

* @return typed search attributes

458

*/

459

SearchAttributes getTypedSearchAttributes();

460

461

/**

462

* Memo attached to this workflow.

463

* @return memo map

464

*/

465

Map<String, Object> getMemo();

466

}

467

```

468

469

### Child Workflow Management

470

471

APIs for managing child workflows within a parent workflow.

472

473

```java { .api }

474

/**

475

* Client stub for child workflow management.

476

*/

477

public interface ChildWorkflowStub {

478

/**

479

* Start child workflow execution.

480

* @param args workflow arguments

481

* @return promise that completes when workflow starts

482

*/

483

Promise<WorkflowExecution> start(Object... args);

484

485

/**

486

* Execute child workflow and get result.

487

* @param resultClass result class

488

* @param args workflow arguments

489

* @return promise with workflow result

490

*/

491

<R> Promise<R> execute(Class<R> resultClass, Object... args);

492

493

/**

494

* Execute child workflow with generic type support.

495

* @param resultClass result class

496

* @param resultType generic type information

497

* @param args workflow arguments

498

* @return promise with workflow result

499

*/

500

<R> Promise<R> execute(Class<R> resultClass, Type resultType, Object... args);

501

502

/**

503

* Get child workflow execution info.

504

* @return workflow execution

505

*/

506

WorkflowExecution getExecution();

507

508

/**

509

* Signal child workflow.

510

* @param signalName signal name

511

* @param args signal arguments

512

*/

513

void signal(String signalName, Object... args);

514

515

/**

516

* Query child workflow.

517

* @param queryType query type

518

* @param resultClass result class

519

* @param args query arguments

520

* @return query result

521

*/

522

<R> R query(String queryType, Class<R> resultClass, Object... args);

523

}

524

```

525

526

**Usage Examples:**

527

528

```java

529

public class ParentWorkflowImpl implements ParentWorkflow {

530

@Override

531

public String orchestrateProcessing(ProcessingRequest request) {

532

// Create child workflow stub

533

DataProcessingWorkflow childWorkflow = Workflow.newChildWorkflowStub(

534

DataProcessingWorkflow.class,

535

ChildWorkflowOptions.newBuilder()

536

.setWorkflowId("data-processing-" + request.getId())

537

.setWorkflowExecutionTimeout(Duration.ofHours(1))

538

.build()

539

);

540

541

// Start multiple child workflows

542

List<Promise<String>> childResults = new ArrayList<>();

543

for (DataChunk chunk : request.getChunks()) {

544

Promise<String> result = childWorkflow.processDataChunk(chunk);

545

childResults.add(result);

546

}

547

548

// Wait for all child workflows to complete

549

Promise<Void> allDone = Promise.allOf(childResults);

550

allDone.get();

551

552

// Aggregate results

553

StringBuilder aggregatedResult = new StringBuilder();

554

for (Promise<String> result : childResults) {

555

aggregatedResult.append(result.get()).append("\n");

556

}

557

558

return aggregatedResult.toString();

559

}

560

}

561

```

562

563

### External Workflow Signaling

564

565

Client stub for signaling external workflows.

566

567

```java { .api }

568

/**

569

* Client stub for signaling external workflows.

570

*/

571

public interface ExternalWorkflowStub {

572

/**

573

* Send signal to external workflow.

574

* @param signalName signal name

575

* @param args signal arguments

576

*/

577

void signal(String signalName, Object... args);

578

579

/**

580

* Cancel external workflow.

581

*/

582

void cancel();

583

584

/**

585

* Get external workflow execution info.

586

* @return workflow execution

587

*/

588

WorkflowExecution getExecution();

589

}

590

```

591

592

**Usage Examples:**

593

594

```java

595

public class CoordinatorWorkflowImpl implements CoordinatorWorkflow {

596

@Override

597

public void coordinateProcessing(List<String> workerWorkflowIds) {

598

// Signal all worker workflows to start

599

List<ExternalWorkflowStub> workers = new ArrayList<>();

600

for (String workflowId : workerWorkflowIds) {

601

ExternalWorkflowStub worker = Workflow.newExternalWorkflowStub(

602

WorkerWorkflow.class,

603

workflowId

604

);

605

workers.add(worker);

606

worker.signal("startProcessing");

607

}

608

609

// Wait for some condition

610

Workflow.sleep(Duration.ofMinutes(30));

611

612

// Signal all workers to stop

613

for (ExternalWorkflowStub worker : workers) {

614

worker.signal("stopProcessing");

615

}

616

}

617

}

618

```

619

620

### Dynamic Workflows

621

622

Interface for implementing workflows that handle multiple workflow types dynamically.

623

624

```java { .api }

625

/**

626

* Interface for implementing workflows that handle multiple workflow types dynamically.

627

*/

628

public interface DynamicWorkflow {

629

/**

630

* Execute dynamic workflow.

631

* @param args workflow arguments

632

* @return workflow result

633

*/

634

Object execute(EncodedValues args);

635

}

636

```

637

638

**Usage Examples:**

639

640

```java

641

public class GenericWorkflowImpl implements DynamicWorkflow {

642

@Override

643

public Object execute(EncodedValues args) {

644

WorkflowInfo info = Workflow.getInfo();

645

String workflowType = info.getWorkflowType();

646

647

switch (workflowType) {

648

case "DataProcessing":

649

return handleDataProcessing(args);

650

case "OrderFulfillment":

651

return handleOrderFulfillment(args);

652

case "UserOnboarding":

653

return handleUserOnboarding(args);

654

default:

655

throw new IllegalArgumentException("Unknown workflow type: " + workflowType);

656

}

657

}

658

659

private Object handleDataProcessing(EncodedValues args) {

660

String dataSource = args.get(0, String.class);

661

ProcessingOptions options = args.get(1, ProcessingOptions.class);

662

663

// Process data...

664

return new ProcessingResult("Processed: " + dataSource);

665

}

666

}

667

```

668

669

### Cancellation Scopes

670

671

Manage cancellation of workflow operations.

672

673

```java { .api }

674

/**

675

* Scope for managing cancellation of workflow operations.

676

*/

677

public interface CancellationScope {

678

/**

679

* Execute runnable in this cancellation scope.

680

* @param runnable code to execute

681

*/

682

void run(Runnable runnable);

683

684

/**

685

* Cancel this scope and all nested operations.

686

*/

687

void cancel();

688

689

/**

690

* Cancel this scope with reason.

691

* @param reason cancellation reason

692

*/

693

void cancel(String reason);

694

695

/**

696

* Check if this scope is canceled.

697

* @return true if canceled

698

*/

699

boolean isCanceled();

700

701

/**

702

* Get cancellation reason if available.

703

* @return optional cancellation reason

704

*/

705

Optional<String> getCancellationReason();

706

}

707

```

708

709

**Usage Examples:**

710

711

```java

712

public class TimeoutWorkflowImpl implements TimeoutWorkflow {

713

@Override

714

public String processWithTimeout(ProcessingRequest request) {

715

CancellationScope timeoutScope = Workflow.newCancellationScope(false, () -> {

716

// Long running operation

717

ProcessingActivity activity = Workflow.newActivityStub(ProcessingActivity.class);

718

return activity.processData(request);

719

});

720

721

// Set up timeout

722

Workflow.newTimer(Duration.ofMinutes(30)).thenRun(() -> {

723

timeoutScope.cancel("Processing timeout");

724

});

725

726

try {

727

timeoutScope.run(() -> {

728

// This will be canceled if timeout occurs

729

});

730

return "Processing completed";

731

} catch (CanceledFailure e) {

732

return "Processing timed out";

733

}

734

}

735

}

736

```

737

738

### Workflow Interface Annotations

739

740

Annotations for defining workflow interfaces and methods.

741

742

```java { .api }

743

/**

744

* Marks interface as a workflow interface.

745

*/

746

@Target(ElementType.TYPE)

747

@Retention(RetentionPolicy.RUNTIME)

748

public @interface WorkflowInterface {

749

}

750

751

/**

752

* Marks the main workflow method.

753

*/

754

@Target(ElementType.METHOD)

755

@Retention(RetentionPolicy.RUNTIME)

756

public @interface WorkflowMethod {

757

/**

758

* Workflow type name.

759

* @return workflow type (default: method name with first letter capitalized)

760

*/

761

String name() default "";

762

}

763

764

/**

765

* Marks workflow signal handler methods.

766

*/

767

@Target(ElementType.METHOD)

768

@Retention(RetentionPolicy.RUNTIME)

769

public @interface SignalMethod {

770

/**

771

* Signal name.

772

* @return signal name (default: method name)

773

*/

774

String name() default "";

775

}

776

777

/**

778

* Marks workflow query handler methods.

779

*/

780

@Target(ElementType.METHOD)

781

@Retention(RetentionPolicy.RUNTIME)

782

public @interface QueryMethod {

783

/**

784

* Query name.

785

* @return query name (default: method name)

786

*/

787

String name() default "";

788

}

789

790

/**

791

* Marks workflow update handler methods.

792

*/

793

@Target(ElementType.METHOD)

794

@Retention(RetentionPolicy.RUNTIME)

795

public @interface UpdateMethod {

796

/**

797

* Update name.

798

* @return update name (default: method name)

799

*/

800

String name() default "";

801

}

802

```

803

804

### Child Workflow Options

805

806

Configuration for child workflow execution.

807

808

```java { .api }

809

/**

810

* Configuration for child workflow execution.

811

*/

812

public final class ChildWorkflowOptions {

813

/**

814

* Creates new builder.

815

* @return new ChildWorkflowOptions builder

816

*/

817

public static Builder newBuilder();

818

819

/**

820

* Creates builder from existing options.

821

* @param options existing options to copy

822

* @return new builder with copied options

823

*/

824

public static Builder newBuilder(ChildWorkflowOptions options);

825

826

/**

827

* Builder for ChildWorkflowOptions.

828

*/

829

public static final class Builder {

830

/**

831

* Child workflow ID.

832

* @param workflowId workflow ID

833

* @return this builder

834

*/

835

public Builder setWorkflowId(String workflowId);

836

837

/**

838

* Workflow execution timeout.

839

* @param timeout execution timeout

840

* @return this builder

841

*/

842

public Builder setWorkflowExecutionTimeout(Duration timeout);

843

844

/**

845

* Workflow run timeout.

846

* @param timeout run timeout

847

* @return this builder

848

*/

849

public Builder setWorkflowRunTimeout(Duration timeout);

850

851

/**

852

* Workflow task timeout.

853

* @param timeout task timeout

854

* @return this builder

855

*/

856

public Builder setWorkflowTaskTimeout(Duration timeout);

857

858

/**

859

* Task queue for child workflow.

860

* @param taskQueue task queue name

861

* @return this builder

862

*/

863

public Builder setTaskQueue(String taskQueue);

864

865

/**

866

* Retry options for child workflow.

867

* @param retryOptions retry options

868

* @return this builder

869

*/

870

public Builder setRetryOptions(RetryOptions retryOptions);

871

872

/**

873

* Cron schedule for child workflow.

874

* @param cronSchedule cron expression

875

* @return this builder

876

*/

877

public Builder setCronSchedule(String cronSchedule);

878

879

/**

880

* Workflow ID reuse policy.

881

* @param workflowIdReusePolicy reuse policy

882

* @return this builder

883

*/

884

public Builder setWorkflowIdReusePolicy(WorkflowIdReusePolicy workflowIdReusePolicy);

885

886

/**

887

* Parent close policy.

888

* @param parentClosePolicy parent close policy

889

* @return this builder

890

*/

891

public Builder setParentClosePolicy(ParentClosePolicy parentClosePolicy);

892

893

/**

894

* Memo for child workflow.

895

* @param memo memo map

896

* @return this builder

897

*/

898

public Builder setMemo(Map<String, Object> memo);

899

900

/**

901

* Search attributes for child workflow.

902

* @param searchAttributes search attributes map

903

* @return this builder

904

*/

905

public Builder setSearchAttributes(Map<String, ?> searchAttributes);

906

907

/**

908

* Typed search attributes for child workflow.

909

* @param searchAttributes typed search attributes

910

* @return this builder

911

*/

912

public Builder setTypedSearchAttributes(SearchAttributes searchAttributes);

913

914

/**

915

* Build the ChildWorkflowOptions.

916

* @return configured ChildWorkflowOptions

917

*/

918

public ChildWorkflowOptions build();

919

}

920

}

921

```

922

923

### Continue As New Options

924

925

Options for continue-as-new functionality.

926

927

```java { .api }

928

/**

929

* Options for continue-as-new functionality.

930

*/

931

public final class ContinueAsNewOptions {

932

/**

933

* Creates new builder.

934

* @return new ContinueAsNewOptions builder

935

*/

936

public static Builder newBuilder();

937

938

/**

939

* Builder for ContinueAsNewOptions.

940

*/

941

public static final class Builder {

942

/**

943

* Workflow type for the new execution.

944

* @param workflowType workflow type name

945

* @return this builder

946

*/

947

public Builder setWorkflowType(String workflowType);

948

949

/**

950

* Task queue for the new execution.

951

* @param taskQueue task queue name

952

* @return this builder

953

*/

954

public Builder setTaskQueue(String taskQueue);

955

956

/**

957

* Workflow run timeout for the new execution.

958

* @param timeout run timeout

959

* @return this builder

960

*/

961

public Builder setWorkflowRunTimeout(Duration timeout);

962

963

/**

964

* Workflow task timeout for the new execution.

965

* @param timeout task timeout

966

* @return this builder

967

*/

968

public Builder setWorkflowTaskTimeout(Duration timeout);

969

970

/**

971

* Memo for the new execution.

972

* @param memo memo map

973

* @return this builder

974

*/

975

public Builder setMemo(Map<String, Object> memo);

976

977

/**

978

* Search attributes for the new execution.

979

* @param searchAttributes search attributes map

980

* @return this builder

981

*/

982

public Builder setSearchAttributes(Map<String, ?> searchAttributes);

983

984

/**

985

* Typed search attributes for the new execution.

986

* @param searchAttributes typed search attributes

987

* @return this builder

988

*/

989

public Builder setTypedSearchAttributes(SearchAttributes searchAttributes);

990

991

/**

992

* Build the ContinueAsNewOptions.

993

* @return configured ContinueAsNewOptions

994

*/

995

public ContinueAsNewOptions build();

996

}

997

}

998

```

999

1000

**Usage Examples:**

1001

1002

```java

1003

public class ProcessingWorkflowImpl implements ProcessingWorkflow {

1004

@Override

1005

public void processInBatches(BatchRequest request) {

1006

List<DataItem> currentBatch = request.getBatch();

1007

1008

// Process current batch

1009

for (DataItem item : currentBatch) {

1010

processItem(item);

1011

}

1012

1013

// Check if more batches to process

1014

if (request.hasMoreBatches()) {

1015

BatchRequest nextRequest = request.getNextBatch();

1016

1017

// Continue as new to avoid history growth

1018

Workflow.continueAsNew(

1019

ContinueAsNewOptions.newBuilder()

1020

.setMemo(Map.of("processed_batches", request.getProcessedBatchCount() + 1))

1021

.build(),

1022

nextRequest

1023

);

1024

}

1025

}

1026

}

1027

```