add early code examples and cross links

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>
This commit is contained in:
Hannah Hunter 2024-01-02 16:11:13 -05:00
parent bec3842e94
commit a7e270e02f
6 changed files with 141 additions and 17 deletions

View File

@ -169,13 +169,40 @@ public class DemoWorkflowActivity implements WorkflowActivity {
<!--go-->
Define the workflow activities you'd like your workflow to perform. Activities are wrapped in the public `DemoWorkflowActivity` class, which implements the workflow activities.
Define the workflow activities you'd like your workflow to perform. Activities are wrapped in the public `callActivityOptions` class, which implements the workflow activities.
```go
type ActivityContext struct {
ctx task.ActivityContext
}
func (wfac *ActivityContext) GetInput(v interface{}) error {
return wfac.ctx.GetInput(&v)
}
func (wfac *ActivityContext) Context() context.Context {
return wfac.ctx.Context()
}
type callActivityOption func(*callActivityOptions) error
type callActivityOptions struct {
rawInput *wrapperspb.StringValue
}
func WithActivityInput(input any) callActivityOption {
return func(opt *callActivityOptions) error {
data, err := marshalData(input)
if err != nil {
return err
}
opt.rawInput = wrapperspb.String(string(data))
return nil
}
}
```
[See the Go SDK workflow activity example in context.](https://github.com/dapr/java-sdk/blob/master/examples/src/main/java/io/dapr/examples/workflows/DemoWorkflowActivity.java)
[See the Go SDK workflow activity example in context.](todo)
{{% /codetab %}}
@ -289,10 +316,61 @@ public class DemoWorkflowWorker {
Next, register the workflow with the `WorkflowRuntimeBuilder` and start the workflow runtime.
```go
package workflow
// Register workflow
func (wr *WorkflowRuntime) RegisterWorkflow(w Workflow) error {
wrappedOrchestration := wrapWorkflow(w)
// get decorator for workflow
name, err := getDecorator(w)
if err != nil {
return fmt.Errorf("failed to get workflow decorator: %v", err)
}
err = wr.tasks.AddOrchestratorN(name, wrappedOrchestration)
return err
}
// Activity wrapper
func wrapActivity(a Activity) task.Activity {
return func(ctx task.ActivityContext) (any, error) {
aCtx := ActivityContext{ctx: ctx}
return a(aCtx)
}
}
// Register wrapped activity
func (wr *WorkflowRuntime) RegisterActivity(a Activity) error {
wrappedActivity := wrapActivity(a)
// get decorator for activity
name, err := getDecorator(a)
if err != nil {
return fmt.Errorf("failed to get activity decorator: %v", err)
}
err = wr.tasks.AddActivityN(name, wrappedActivity)
return err
}
// Start workflow runtime
func (wr *WorkflowRuntime) Start() error {
// go func start
go func() {
err := wr.client.StartWorkItemListener(context.Background(), wr.tasks)
if err != nil {
log.Fatalf("failed to start work stream: %v", err)
}
}()
<-wr.quit
return nil
}
```
[See the Go SDK workflow in context.](https://github.com/dapr/java-sdk/blob/master/examples/src/main/java/io/dapr/examples/workflows/DemoWorkflowWorker.java)
[See the Go SDK workflow in context.](todo)
{{% /codetab %}}
@ -515,7 +593,7 @@ public class DemoWorkflow extends Workflow {
<!--go-->
[As in the following example](https://github.com/dapr/java-sdk/blob/master/examples/src/main/java/io/dapr/examples/workflows/DemoWorkflow.java), a hello-world application using the Go SDK and Dapr Workflow would include:
[As in the following example](todo), a hello-world application using the Go SDK and Dapr Workflow would include:
- A Go package called `todo` to receive the Go SDK client capabilities.
- An import of `todo`
@ -527,7 +605,7 @@ public class DemoWorkflow extends Workflow {
```
[See the full Go SDK workflow example in context.](https://github.com/dapr/java-sdk/blob/master/examples/src/main/java/io/dapr/examples/workflows/DemoWorkflow.java)
[See the full Go SDK workflow example in context.](todo)
{{% /codetab %}}

View File

@ -167,19 +167,58 @@ public class DemoWorkflowClient {
<!--Go-->
{{% codetab %}}
Manage your workflow within your code. [In the workflow example from the Go SDK](https://github.com/dapr/java-sdk/blob/master/examples/src/main/java/io/dapr/examples/workflows/DemoWorkflowClient.java), the workflow is registered in the code using the following APIs:
Manage your workflow within your code. [In the workflow example from the Go SDK](todo), the workflow is registered in the code using the following APIs:
- **scheduleNewWorkflow**: Starts a new workflow instance
- **getInstanceState**: Get information on the status of the workflow
- **waitForInstanceStart**: Pauses or suspends a workflow instance that can later be resumed
- **raiseEvent**: Raises events/tasks for the running workflow instance
- **waitForInstanceCompletion**: Waits for the workflow to complete its tasks
- **purgeInstance**: Removes all metadata related to a specific workflow instance
- **terminateWorkflow**: Terminates the workflow
- **purgeInstance**: Removes all metadata related to a specific workflow
- **StartWorkflow**: Starts a new workflow instance
- **GetWorkflow**: Get information on the status of the workflow
- **PauseWorkflow**: Pauses or suspends a workflow instance that can later be resumed
- **RaiseEventWorkflow**: Raises events/tasks for the running workflow instance
- **ResumeWorkflow**: Waits for the workflow to complete its tasks
- **PurgeWorkflow**: Removes all metadata related to a specific workflow instance
- **TerminateWorkflow**: Terminates the workflow
```go
// StartWorkflowAlpha1 starts a workflow.
StartWorkflowAlpha1(ctx context.Context, req *StartWorkflowRequest) (*StartWorkflowResponse, error)
// GetWorkflowAlpha1 gets a workflow.
GetWorkflowAlpha1(ctx context.Context, req *GetWorkflowRequest) (*GetWorkflowResponse, error)
// PurgeWorkflowAlpha1 purges a workflow.
PurgeWorkflowAlpha1(ctx context.Context, req *PurgeWorkflowRequest) error
// TerminateWorkflowAlpha1 terminates a workflow.
TerminateWorkflowAlpha1(ctx context.Context, req *TerminateWorkflowRequest) error
// PauseWorkflowAlpha1 pauses a workflow.
PauseWorkflowAlpha1(ctx context.Context, req *PauseWorkflowRequest) error
// ResumeWorkflowAlpha1 resumes a workflow.
ResumeWorkflowAlpha1(ctx context.Context, req *ResumeWorkflowRequest) error
// RaiseEventWorkflowAlpha1 raises an event for a workflow.
RaiseEventWorkflowAlpha1(ctx context.Context, req *RaiseEventWorkflowRequest) error
// StartWorkflowBeta1 starts a workflow.
StartWorkflowBeta1(ctx context.Context, req *StartWorkflowRequest) (*StartWorkflowResponse, error)
// GetWorkflowBeta1 gets a workflow.
GetWorkflowBeta1(ctx context.Context, req *GetWorkflowRequest) (*GetWorkflowResponse, error)
// PurgeWorkflowBeta1 purges a workflow.
PurgeWorkflowBeta1(ctx context.Context, req *PurgeWorkflowRequest) error
// TerminateWorkflowBeta1 terminates a workflow.
TerminateWorkflowBeta1(ctx context.Context, req *TerminateWorkflowRequest) error
// PauseWorkflowBeta1 pauses a workflow.
PauseWorkflowBeta1(ctx context.Context, req *PauseWorkflowRequest) error
// ResumeWorkflowBeta1 resumes a workflow.
ResumeWorkflowBeta1(ctx context.Context, req *ResumeWorkflowRequest) error
// RaiseEventWorkflowBeta1 raises an event for a workflow.
RaiseEventWorkflowBeta1(ctx context.Context, req *RaiseEventWorkflowRequest) error
```
{{% /codetab %}}

View File

@ -196,4 +196,5 @@ See the [Reminder usage and execution guarantees section]({{< ref "workflow-arch
- Try out the following examples:
- [Python](https://github.com/dapr/python-sdk/tree/master/examples/demo_workflow)
- [.NET](https://github.com/dapr/dotnet-sdk/tree/master/examples/Workflow)
- [Java](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/workflows)
- [Java](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/workflows)
- [Go example](todo)

View File

@ -411,4 +411,8 @@ To work around these constraints:
- [Try out Dapr Workflow using the quickstart]({{< ref workflow-quickstart.md >}})
- [Workflow overview]({{< ref workflow-overview.md >}})
- [Workflow API reference]({{< ref workflow_api.md >}})
- [Try out the .NET example](https://github.com/dapr/dotnet-sdk/tree/master/examples/Workflow)
- Try out the following examples:
- [Python](https://github.com/dapr/python-sdk/tree/master/examples/demo_workflow)
- [.NET](https://github.com/dapr/dotnet-sdk/tree/master/examples/Workflow)
- [Java](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/workflows)
- [Go example](todo)

View File

@ -114,3 +114,4 @@ Watch [this video for an overview on Dapr Workflow](https://youtu.be/s1p9MNl4VGo
- [.NET example](https://github.com/dapr/dotnet-sdk/tree/master/examples/Workflow)
- [Python example](https://github.com/dapr/python-sdk/tree/master/examples/demo_workflow)
- [Java example](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/workflows)
- [Go example](todo)

View File

@ -789,4 +789,5 @@ External events don't have to be directly triggered by humans. They can also be
- Try out the following examples:
- [Python](https://github.com/dapr/python-sdk/tree/master/examples/demo_workflow)
- [.NET](https://github.com/dapr/dotnet-sdk/tree/master/examples/Workflow)
- [Java](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/workflows)
- [Java](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/workflows)
- [Go example](todo)