Skip to content

Commit e93b654

Browse files
authored
Merge branch 'v1.12' into java_features
2 parents 046b563 + 88a109b commit e93b654

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-patterns.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,41 @@ public override async Task<object> RunAsync(WorkflowContext context, MyEntitySta
464464
<!--java-->
465465

466466
```java
467-
todo
467+
public class MonitorWorkflow extends Workflow {
468+
469+
@Override
470+
public WorkflowStub create() {
471+
return ctx -> {
472+
473+
Duration nextSleepInterval;
474+
475+
var status = ctx.callActivity(DemoWorkflowStatusActivity.class.getName(), DemoStatusActivityOutput.class).await();
476+
var isHealthy = status.getIsHealthy();
477+
478+
if (isHealthy) {
479+
// Check less frequently when in a healthy state
480+
nextSleepInterval = Duration.ofMinutes(60);
481+
} else {
482+
483+
ctx.callActivity(DemoWorkflowAlertActivity.class.getName()).await();
484+
485+
// Check more frequently when in an unhealthy state
486+
nextSleepInterval = Duration.ofMinutes(5);
487+
}
488+
489+
// Put the workflow to sleep until the determined time
490+
// Note: ctx.createTimer() method is not supported in the Java SDK yet
491+
try {
492+
TimeUnit.SECONDS.sleep(nextSleepInterval.getSeconds());
493+
} catch (InterruptedException e) {
494+
throw new RuntimeException(e);
495+
}
496+
497+
// Restart from the beginning with the updated state
498+
ctx.continueAsNew();
499+
}
500+
}
501+
}
468502
```
469503

470504
{{% /codetab %}}

0 commit comments

Comments
 (0)