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

Build first app go v2 #348

Merged
merged 11 commits into from
Dec 18, 2024
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
780 changes: 567 additions & 213 deletions docs/getting_started/go/hello_world_in_go/index.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion docs/getting_started/php/hello_world_in_php/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ class GreetingWorkflow implements GreetingWorkflowInterface
*/
$this->greetingActivity = Workflow::newActivityStub(
GreetingActivityInterface::class,
ActivityOptions::new()->withStartToCloseTimeout(CarbonInterval::seconds(2))
ActivityOptions::new()
->withStartToCloseTimeout(CarbonInterval::seconds(2))
->withRetryOptions(RetryOptions::new()->withMaximumAttempts(1))
);
}

Expand Down
43 changes: 24 additions & 19 deletions docs/getting_started/typescript/hello_world_in_typescript/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,25 +234,30 @@ async function run() {
address: 'localhost:7233',
// TLS and gRPC metadata configuration goes here.
});
// Step 2: Register Workflows and Activities with the Worker.
const worker = await Worker.create({
connection,
namespace: 'default',
taskQueue: 'hello-world',
// Workflows are registered using a path as they run in a separate JS context.
workflowsPath: require.resolve('./workflows'),
activities,
});
try {
// Step 2: Register Workflows and Activities with the Worker.
const worker = await Worker.create({
connection,
namespace: 'default',
taskQueue: 'hello-world',
// Workflows are registered using a path as they run in a separate JS context.
workflowsPath: require.resolve('./workflows'),
activities,
});

// Step 3: Start accepting tasks on the `hello-world` queue
//
// The worker runs until it encounters an unexpected error or the process receives a shutdown signal registered on
// the SDK Runtime object.
//
// By default, worker logs are written via the Runtime logger to STDERR at INFO level.
//
// See https://typescript.temporal.io/api/classes/worker.Runtime#install to customize these defaults.
await worker.run();
// Step 3: Start accepting tasks on the `hello-world` queue
//
// The worker runs until it encounters an unexpected error or the process receives a shutdown signal registered on
// the SDK Runtime object.
//
// By default, worker logs are written via the Runtime logger to STDERR at INFO level.
//
// See https://typescript.temporal.io/api/classes/worker.Runtime#install to customize these defaults.
await worker.run();
} finally {
// Close the connection once the worker has stopped
await connection.close();
}
}

run().catch((err) => {
Expand Down Expand Up @@ -509,7 +514,7 @@ describe('Example workflow', () => {
args: ['Temporal'],
workflowId: 'test',
taskQueue,
})
}),
);
assert.equal(result, 'Hello, Temporal!');
});
Expand Down
13 changes: 4 additions & 9 deletions docs/tutorials/go/background-check/durable-execution.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,9 @@ Run the tests in the test directory (`go test`).
If the Workflow Definition and the Event History are incompatible then the test fails.

<!--SNIPSTART go-durability-chapter-replay-test-->

[docs/tutorials/go/background-check/code/durability/tests/backgroundcheck_test.go](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/go/background-check/code/durability/tests/backgroundcheck_test.go)

```go

// TestReplayWorkflowHistoryFromFile tests for Event History compatibility.
func (s *UnitTestSuite) TestReplayWorkflowHistoryFromFile() {
// Create a new Replayer
Expand All @@ -162,8 +161,8 @@ func (s *UnitTestSuite) TestReplayWorkflowHistoryFromFile() {
err := replayer.ReplayWorkflowHistoryFromJSONFile(nil, "backgroundcheck_workflow_event_history.json")
s.NoError(err)
}
```

```
<!--SNIPEND-->

### Why add a Replay test? {#why-replay-test}
Expand Down Expand Up @@ -208,9 +207,7 @@ The following are some common operations that **can't** be done inside of a Work
One way to produce a non-deterministic error is to use a random number to determine whether to sleep inside the Workflow.

<!--SNIPSTART go-durability-chapter-non-deterministic-workflow-->

[docs/tutorials/go/background-check/code/durability/workflows/backgroundcheck_non_deterministic_code.go](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/go/background-check/code/durability/workflows/backgroundcheck_non_deterministic_code.go)

```go
// CAUTION! Do not use this code!
package workflows
Expand Down Expand Up @@ -247,8 +244,8 @@ func BackgroundCheckNonDeterministic(ctx workflow.Context, param string) (string
}
return ssnTraceResult, nil
}
```

```
<!--SNIPEND-->

If you run the BackgroundCheckNonDeterministic Workflow enough times, eventually you will see a Workflow Task failure.
Expand Down Expand Up @@ -399,9 +396,7 @@ The Temporal SDK offers both a `workflow.StartTimer()` API, and a `workflow.Slee
Use the `workflow.GetLogger` API to log from Workflows to avoid seeing repeated logs from the Replay of the Workflow code.

<!--SNIPSTART go-durability-chapter-workflow-->

[docs/tutorials/go/background-check/code/durability/workflows/backgroundcheck.go](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/go/background-check/code/durability/workflows/backgroundcheck.go)

```go
package workflows

Expand Down Expand Up @@ -439,8 +434,8 @@ func BackgroundCheck(ctx workflow.Context, param string) (string, error) {
// Make the results of the Workflow available
return ssnTraceResult, nil
}
```

```
<!--SNIPEND-->

### Inspect the new Event History {#inspect-new-event-history}
Expand Down
34 changes: 10 additions & 24 deletions docs/tutorials/go/background-check/project-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,7 @@ In the Temporal Go SDK programming model, a [Workflow Definition](https://docs.t
The `BackgroundCheck` function below is an example of a basic Workflow Definition.

<!--SNIPSTART setup-chapter-workflow-->

[docs/tutorials/go/background-check/code/setup/workflows/backgroundcheck.go](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/go/background-check/code/setup/workflows/backgroundcheck.go)

```go
package workflows

Expand Down Expand Up @@ -393,8 +391,8 @@ func BackgroundCheck(ctx workflow.Context, param string) (string, error) {
// Make the results of the Workflow available
return ssnTraceResult, nil
}
```

```
<!--SNIPEND-->

The first parameter of a Go-based Workflow Definition must be of the [`workflow.Context`](https://pkg.go.dev/go.temporal.io/sdk/workflow#Context) type.
Expand Down Expand Up @@ -424,9 +422,7 @@ In the Temporal Go SDK programming model, an Activity is an exportable function
Below is an example of an Activity defined as a function.

<!--SNIPSTART setup-chapter-activity-->

[docs/tutorials/go/background-check/code/setup/activities/ssntraceactivity.go](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/go/background-check/code/setup/activities/ssntraceactivity.go)

```go
package activities

Expand All @@ -441,8 +437,8 @@ func SSNTraceActivity(ctx context.Context, param string) (*string, error) {
result := "pass"
return &result, nil
}
```

```
<!--SNIPEND-->

The first parameter of an Activity Definition is `context.Context`.
Expand All @@ -464,9 +460,7 @@ To run a Worker Process with a local development server, define the following st
In regards to organization, we recommend keeping Worker code separate from Workflow and Activity code.

<!--SNIPSTART setup-chapter-worker-dev-->

[docs/tutorials/go/background-check/code/setup/dev_server_worker/main.go](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/go/background-check/code/setup/dev_server_worker/main.go)

```go
package main

Expand Down Expand Up @@ -503,8 +497,8 @@ func main() {
log.Fatalln("Unable to start the Worker Process", err)
}
}
```

```
<!--SNIPEND-->

:::info Auto restart worker when code changes
Expand All @@ -527,9 +521,7 @@ A Temporal Cloud Worker requires that you specify the following in the Client co
- Certificate and private key associated with the Namespace

<!--SNIPSTART setup-chapter-worker-cloud-->

[docs/tutorials/go/background-check/code/setup/cloud_worker/main.go](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/go/background-check/code/setup/cloud_worker/main.go)

```go
package main

Expand Down Expand Up @@ -590,8 +582,8 @@ func main() {
log.Fatalln("Unable to start the Worker Process", err)
}
}
```

```
<!--SNIPEND-->

To run a Temporal Cloud Worker, you'll change some parameters in your Client connection code, such as updating the namespace and gRPC endpoint.
Expand Down Expand Up @@ -673,9 +665,7 @@ Copy the IP address part.
Set IP address, port, and Namespace in the Temporal Client options.

<!--SNIPSTART setup-chapter-worker-self-hosted-->

[docs/tutorials/go/background-check/code/setup/self_hosted_worker/main.go](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/go/background-check/code/setup/self_hosted_worker/main.go)

```go
package main

Expand Down Expand Up @@ -717,8 +707,8 @@ func main() {
log.Fatalln("Unable to start the Worker Process", err)
}
}
```

```
<!--SNIPEND-->

#### Build and deploy Docker image {#dockerfile}
Expand Down Expand Up @@ -946,9 +936,7 @@ Each Temporal SDK has a testing suite that can be used in conjunction with a typ
In the Temporal Go SDK, the `testsuite` package (https://pkg.go.dev/go.temporal.io/sdk/testsuite) provides a test environment in which the Workflow and Activity code may be run for test purposes.

<!--SNIPSTART setup-chapter-test-framework-->

[docs/tutorials/go/background-check/code/setup/tests/backgroundcheckboilerplate_test.go](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/go/background-check/code/setup/tests/backgroundcheckboilerplate_test.go)

```go
package setup

Expand Down Expand Up @@ -976,8 +964,8 @@ func Test_BackgroundCheckApplication(t *testing.T) {
s := &UnitTestSuite{}
suite.Run(t, s)
}
```

```
<!--SNIPEND-->

In this example, we use a custom struct that absorbs both the testing functionality from testify (https://pkg.go.dev/github.com/stretchr/testify/suite) via `suite.Suite` and the testing functionality from the Temporal test framework via `testsuite.WorkflowTestSuite`.
Expand All @@ -995,10 +983,9 @@ We can test Workflow code for the following conditions:
We can also perform a Workflow Replay test, and we'll provide detailed coverage of this topic in another section.

<!--SNIPSTART setup-chapter-test-workflow-->

[docs/tutorials/go/background-check/code/setup/tests/backgroundcheckboilerplate_test.go](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/go/background-check/code/setup/tests/backgroundcheckboilerplate_test.go)

```go

const ssn string = "555-55-5555"

// Test_BackgroundCheckWorkflow tests the BackgroundCheck Workflow function
Expand All @@ -1022,8 +1009,8 @@ func (s *UnitTestSuite) Test_BackgroundCheckWorkflow() {
s.NoError(env.GetWorkflowResult(&result))
s.Equal(result, ssnTraceResult)
}
```

```
<!--SNIPEND-->

Calling `env.ExecuteWorkflow(...)` executes the Workflow logic and any invoked Activities inside the test process.
Expand All @@ -1045,10 +1032,9 @@ We can test Activity code for the following conditions:
- Activity return values. Check to ensure the return value is expected.

<!--SNIPSTART setup-chapter-test-activity-->

[docs/tutorials/go/background-check/code/setup/tests/backgroundcheckboilerplate_test.go](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/go/background-check/code/setup/tests/backgroundcheckboilerplate_test.go)

```go

// Test_SSNTraceActivity tests the SSNTraceActivity function
func (s *UnitTestSuite) Test_SSNTraceActivity() {
// Create a test environment
Expand All @@ -1065,6 +1051,6 @@ func (s *UnitTestSuite) Test_SSNTraceActivity() {
// Check for the expected return value.
s.Equal("pass", result)
}
```

```
<!--SNIPEND-->
10 changes: 1 addition & 9 deletions docs/tutorials/java/background-check/durable-execution.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ From the Workflow details page you can copy the Event History from the JSON tab
Add the Replay test to the set of application tests.

<!--SNIPSTART java-durability-chapter-replay-test {"selectedLines":["56-65"]}-->

[docs/tutorials/java/background-check/code/backgroundcheck-replay/src/test/java/backgroundcheckreplay/BackgroundCheckReplayWorkflowTest.java](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/java/background-check/code/backgroundcheck-replay/src/test/java/backgroundcheckreplay/BackgroundCheckReplayWorkflowTest.java)

```java
// ...
@Test
Expand All @@ -157,7 +155,6 @@ Add the Replay test to the set of application tests.
}
}
```

<!--SNIPEND-->

### Why add a Replay test? {#why-replay-test}
Expand Down Expand Up @@ -197,9 +194,7 @@ The following are some common operations that **can't** be done inside of a Work
One way to produce a non-deterministic error is to use a random number to determine whether to sleep inside the Workflow.

<!--SNIPSTART java-durability-chapter-non-deterministic-workflow-implementation-->

[docs/tutorials/java/background-check/code/backgroundcheck-replay/src/main/java/backgroundcheckreplay/BackgroundCheckReplayNonDeterministicWorkflowImpl.java](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/java/background-check/code/backgroundcheck-replay/src/main/java/backgroundcheckreplay/BackgroundCheckReplayNonDeterministicWorkflowImpl.java)

```java
package backgroundcheckreplay;

Expand Down Expand Up @@ -242,7 +237,6 @@ public class BackgroundCheckReplayNonDeterministicWorkflowImpl implements Backgr

}
```

<!--SNIPEND-->

## Non-deterministic code changes {#durability-through-replays}
Expand Down Expand Up @@ -325,9 +319,7 @@ The Temporal SDK offers both a `Workflow.newTimer()` API, and a `Workflow.sleep(
Use the `Workflow.getLogger` API to log from Workflows to suppress repeated logs from the Replay of the Workflow code.

<!--SNIPSTART java-durability-chapter-workflow-->

[docs/tutorials/java/background-check/code/backgroundcheck-replay/src/main/java/backgroundcheckreplay/BackgroundCheckReplayWorkflowImpl.java](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/java/background-check/code/backgroundcheck-replay/src/main/java/backgroundcheckreplay/BackgroundCheckReplayWorkflowImpl.java)

```java
package backgroundcheckreplay;

Expand Down Expand Up @@ -369,8 +361,8 @@ public class BackgroundCheckReplayWorkflowImpl implements BackgroundCheckReplayW
}

}
```

```
<!--SNIPEND-->

### Inspect the new Event History {#inspect-new-event-history}
Expand Down
Loading
Loading