Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Workflow] Add java monitor pattern example #3774

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,41 @@ public override async Task<object> RunAsync(WorkflowContext context, MyEntitySta
<!--java-->

```java
todo
public class MonitorWorkflow extends Workflow {

@Override
public WorkflowStub create() {
return ctx -> {

Duration nextSleepInterval;

var status = ctx.callActivity(DemoWorkflowStatusActivity.class.getName(), DemoStatusActivityOutput.class).await();
var isHealthy = status.getIsHealthy();

if (isHealthy) {
// Check less frequently when in a healthy state
nextSleepInterval = Duration.ofMinutes(60);
} else {

ctx.callActivity(DemoWorkflowAlertActivity.class.getName()).await();

// Check more frequently when in an unhealthy state
nextSleepInterval = Duration.ofMinutes(5);
}

// Put the workflow to sleep until the determined time
// Note: ctx.createTimer() method is not supported in the Java SDK yet
try {
TimeUnit.SECONDS.sleep(nextSleepInterval.getSeconds());
} catch (InterruptedException e) {
throw new RuntimeException(e);
}

// Restart from the beginning with the updated state
ctx.continueAsNew();
}
}
}
```

{{% /codetab %}}
Expand Down