-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98fac0c
commit 2087727
Showing
9 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
core/src/main/java/io/temporal/samples/workflowtimeout/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
worker: | ||
ls *.java | entr -r \ | ||
sh -c 'cd $$(git rev-parse --show-toplevel) && ./gradlew -q execute -P mainClass=io.temporal.samples.basic.MyWorker' | ||
|
||
run: | ||
cd $$(git rev-parse --show-toplevel) && \ | ||
./gradlew -q execute -P mainClass=io.temporal.samples.basic.MyStarter | ||
|
||
.PHONY: run worker |
11 changes: 11 additions & 0 deletions
11
core/src/main/java/io/temporal/samples/workflowtimeout/MyActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.temporal.samples.workflowtimeout; | ||
|
||
import io.temporal.activity.ActivityInterface; | ||
import io.temporal.activity.ActivityMethod; | ||
|
||
@ActivityInterface | ||
public interface MyActivity { | ||
|
||
@ActivityMethod | ||
int myActivityMethod(); | ||
} |
8 changes: 8 additions & 0 deletions
8
core/src/main/java/io/temporal/samples/workflowtimeout/MyActivityImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.temporal.samples.workflowtimeout; | ||
|
||
public class MyActivityImpl implements MyActivity { | ||
@Override | ||
public int myActivityMethod() { | ||
return 7; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
core/src/main/java/io/temporal/samples/workflowtimeout/MyStarter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.temporal.samples.workflowtimeout; | ||
|
||
import io.temporal.api.enums.v1.WorkflowIdConflictPolicy; | ||
import io.temporal.client.WorkflowClient; | ||
import io.temporal.client.WorkflowOptions; | ||
import io.temporal.serviceclient.WorkflowServiceStubs; | ||
|
||
public class MyStarter { | ||
|
||
static final String WORKFLOW_ID = "wid"; | ||
|
||
public static void main(String[] args) throws Exception { | ||
|
||
WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); | ||
|
||
WorkflowClient client = WorkflowClient.newInstance(service); | ||
|
||
WorkflowOptions workflowOptions = | ||
WorkflowOptions.newBuilder() | ||
.setTaskQueue(MyWorker.TASK_QUEUE) | ||
.setWorkflowId(WORKFLOW_ID) | ||
.setWorkflowIdConflictPolicy( | ||
WorkflowIdConflictPolicy.WORKFLOW_ID_CONFLICT_POLICY_TERMINATE_EXISTING) | ||
.setWorkflowExecutionTimeout(java.time.Duration.ofSeconds(2)) | ||
.build(); | ||
MyWorkflow workflow = client.newWorkflowStub(MyWorkflow.class, workflowOptions); | ||
|
||
WorkflowClient.start(workflow::run); | ||
|
||
int upResult = workflow.myUpdate(); | ||
System.out.println("upResult: " + upResult); | ||
|
||
int wfResult = workflow.run(); | ||
System.out.println("wfResult: " + wfResult); | ||
|
||
System.exit(0); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
core/src/main/java/io/temporal/samples/workflowtimeout/MyWorker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.temporal.samples.workflowtimeout; | ||
|
||
import io.temporal.client.WorkflowClient; | ||
import io.temporal.serviceclient.WorkflowServiceStubs; | ||
import io.temporal.worker.Worker; | ||
import io.temporal.worker.WorkerFactory; | ||
|
||
public class MyWorker { | ||
static final String TASK_QUEUE = "tq"; | ||
|
||
public static void main(String[] args) throws Exception { | ||
|
||
WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); | ||
|
||
WorkflowClient client = WorkflowClient.newInstance(service); | ||
|
||
WorkerFactory factory = WorkerFactory.newInstance(client); | ||
Worker worker = factory.newWorker(TASK_QUEUE); | ||
worker.registerWorkflowImplementationTypes(MyWorkflowImpl.class); | ||
worker.registerActivitiesImplementations(new MyActivityImpl()); | ||
factory.start(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
core/src/main/java/io/temporal/samples/workflowtimeout/MyWorkflow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.temporal.samples.workflowtimeout; | ||
|
||
import io.temporal.workflow.UpdateMethod; | ||
import io.temporal.workflow.WorkflowInterface; | ||
import io.temporal.workflow.WorkflowMethod; | ||
|
||
@WorkflowInterface | ||
public interface MyWorkflow { | ||
@WorkflowMethod | ||
int run(); | ||
|
||
@UpdateMethod | ||
int myUpdate(); | ||
} |
34 changes: 34 additions & 0 deletions
34
core/src/main/java/io/temporal/samples/workflowtimeout/MyWorkflowImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.temporal.samples.workflowtimeout; | ||
|
||
import io.temporal.activity.ActivityOptions; | ||
import io.temporal.common.RetryOptions; | ||
import io.temporal.workflow.Workflow; | ||
import java.time.Duration; | ||
|
||
public class MyWorkflowImpl implements MyWorkflow { | ||
|
||
private final MyActivity activity = | ||
Workflow.newActivityStub( | ||
MyActivity.class, | ||
ActivityOptions.newBuilder() | ||
.setStartToCloseTimeout(Duration.ofSeconds(2)) | ||
.setRetryOptions(RetryOptions.newBuilder().setMaximumAttempts(1).build()) | ||
.build()); | ||
|
||
// private boolean done; | ||
|
||
@Override | ||
public int run() { | ||
Workflow.sleep(Duration.ofSeconds(3)); | ||
// Workflow.await(() -> done); | ||
return 8; | ||
} | ||
|
||
@Override | ||
public int myUpdate() { | ||
Workflow.sleep(Duration.ofSeconds(2)); | ||
int result = activity.myActivityMethod(); | ||
// done = true; | ||
return result; | ||
} | ||
} |