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] Update for JavaScript SDK #3896

Merged
merged 19 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -34,7 +34,7 @@ The Dapr sidecar doesn’t load any workflow definitions. Rather, the sidecar si

[Workflow activities]({{< ref "workflow-features-concepts.md#workflow-activites" >}}) are the basic unit of work in a workflow and are the tasks that get orchestrated in the business process.

{{< tabs Python ".NET" Java >}}
{{< tabs Python JavaScript ".NET" Java >}}

{{% codetab %}}

Expand All @@ -52,6 +52,21 @@ def hello_act(ctx: WorkflowActivityContext, input):
[See the `hello_act` workflow activity in context.](https://github.com/dapr/python-sdk/blob/master/examples/demo_workflow/app.py#LL40C1-L43C59)


{{% /codetab %}}

{{% codetab %}}

<!--javascript-->

Define the workflow activities you'd like your workflow to perform. Activities are a function definition and can take inputs and outputs. The following example creates a counter (activity) called `hello_act` that notifies users of the current counter value. `hello_act` is a function derived from a class called `WorkflowActivityContext`.

```javascript

```

[See the workflow activity in context.](https://github.com/dapr/python-sdk/blob/master/examples/demo_workflow/app.py#LL40C1-L43C59)
hhunter-ms marked this conversation as resolved.
Show resolved Hide resolved


{{% /codetab %}}

{{% codetab %}}
Expand Down Expand Up @@ -172,7 +187,7 @@ public class DemoWorkflowActivity implements WorkflowActivity {

Next, register and call the activites in a workflow.

{{< tabs Python ".NET" Java >}}
{{< tabs Python JavaScript ".NET" Java >}}

{{% codetab %}}

Expand All @@ -193,6 +208,21 @@ def hello_world_wf(ctx: DaprWorkflowContext, input):
[See the `hello_world_wf` workflow in context.](https://github.com/dapr/python-sdk/blob/master/examples/demo_workflow/app.py#LL32C1-L38C51)
hhunter-ms marked this conversation as resolved.
Show resolved Hide resolved


{{% /codetab %}}

{{% codetab %}}

<!--javascript-->

The `hello_world_wf` function is derived from a class called `DaprWorkflowContext` with input and output parameter types. It also includes a `yield` statement that does the heavy lifting of the workflow and calls the workflow activities.

```javascript

```

[See the `hello_world_wf` workflow in context.](https://github.com/dapr/python-sdk/blob/master/examples/demo_workflow/app.py#LL32C1-L38C51)


{{% /codetab %}}

{{% codetab %}}
Expand Down Expand Up @@ -275,7 +305,7 @@ public class DemoWorkflowWorker {

Finally, compose the application using the workflow.

{{< tabs Python ".NET" Java >}}
{{< tabs Python JavaScript ".NET" Java >}}

{{% codetab %}}

Expand Down Expand Up @@ -364,6 +394,25 @@ if __name__ == '__main__':
```


{{% /codetab %}}

{{% codetab %}}

<!--javascript-->

[In the following example](https://github.com/dapr/python-sdk/blob/master/examples/demo_workflow/app.py), for a basic JavaScript hello world application using the Go SDK, your project code would include:
hhunter-ms marked this conversation as resolved.
Show resolved Hide resolved

- A JavaScript package called `todo` to receive the Go SDK capabilities.
hhunter-ms marked this conversation as resolved.
Show resolved Hide resolved
- A builder with extensions called:
- `WorkflowRuntime`: Allows you to register workflows and workflow activities
- `DaprWorkflowContext`: Allows you to [create workflows]({{< ref "#write-the-workflow" >}})
- `WorkflowActivityContext`: Allows you to [create workflow activities]({{< ref "#write-the-workflow-activities" >}})
- API calls. In the example below, these calls start, pause, resume, purge, and terminate the workflow.

```go

```

{{% /codetab %}}

{{% codetab %}}
Expand Down Expand Up @@ -504,5 +553,6 @@ Now that you've authored a workflow, learn how to manage it.
- [Workflow API reference]({{< ref workflow_api.md >}})
- Try out the full SDK examples:
- [Python example](https://github.com/dapr/python-sdk/tree/master/examples/demo_workflow)
- [JavaScript example](todo)
hhunter-ms marked this conversation as resolved.
Show resolved Hide resolved
- [.NET example](https://github.com/dapr/dotnet-sdk/tree/master/examples/Workflow)
- [Java example](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/workflows)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Dapr Workflow is currently in beta. [See known limitations for {{% dapr-latest-v

Now that you've [authored the workflow and its activities in your application]({{< ref howto-author-workflow.md >}}), you can start, terminate, and get information about the workflow using HTTP API calls. For more information, read the [workflow API reference]({{< ref workflow_api.md >}}).

{{< tabs Python ".NET" Java HTTP >}}
{{< tabs Python JavaScript ".NET" Java HTTP >}}

<!--Python-->
{{% codetab %}}
Expand Down Expand Up @@ -63,6 +63,24 @@ d.terminate_workflow(instance_id=instanceId, workflow_component=workflowComponen

{{% /codetab %}}

<!--JavaScript-->
{{% codetab %}}

Manage your workflow within your code. In the workflow example from the [Author a workflow]({{< ref "howto-author-workflow.md#write-the-application" >}}) guide, the workflow is registered in the code using the following APIs:
- **start_workflow**: Start an instance of a workflow
- **get_workflow**: Get information on the status of the workflow
- **pause_workflow**: Pauses or suspends a workflow instance that can later be resumed
- **resume_workflow**: Resumes a paused workflow instance
- **raise_workflow_event**: Raise an event on a workflow
- **purge_workflow**: Removes all metadata related to a specific workflow instance
- **terminate_workflow**: Terminate or stop a particular instance of a workflow

```javascript

```

{{% /codetab %}}

<!--NET-->
{{% codetab %}}

Expand Down Expand Up @@ -242,6 +260,7 @@ Learn more about these HTTP calls in the [workflow API reference guide]({{< ref
- [Try out the Workflow quickstart]({{< ref workflow-quickstart.md >}})
- Try out the full SDK examples:
- [Python example](https://github.com/dapr/python-sdk/blob/master/examples/demo_workflow/app.py)
- [JavaScript example](todo)
hhunter-ms marked this conversation as resolved.
Show resolved Hide resolved
- [.NET example](https://github.com/dapr/dotnet-sdk/tree/master/examples/Workflow)
- [Java example](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/workflows)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,15 @@ APIs that generate random numbers, random UUIDs, or the current date are _non-de

For example, instead of this:

{{< tabs ".NET" Java >}}
{{< tabs JavaScript ".NET" Java >}}

{{% codetab %}}

```javascript
// DON'T DO THIS!
```

{{% /codetab %}}

{{% codetab %}}

Expand Down Expand Up @@ -190,7 +198,15 @@ string randomString = GetRandomString();

Do this:

{{< tabs ".NET" Java >}}
{{< tabs JavaScript ".NET" Java >}}

{{% codetab %}}

```javascript
// Do this!!
```

{{% /codetab %}}

{{% codetab %}}

Expand Down Expand Up @@ -224,7 +240,14 @@ Instead, workflows should interact with external state _indirectly_ using workfl

For example, instead of this:

{{< tabs ".NET" Java >}}
{{< tabs JavaScript ".NET" Java >}}

{{% codetab %}}

```javascript
// DON'T DO THIS!
```
{{% /codetab %}}

{{% codetab %}}

Expand All @@ -251,7 +274,15 @@ HttpResponse<String> response = HttpClient.newBuilder().build().send(request, Ht

Do this:

{{< tabs ".NET" Java >}}
{{< tabs JavaScript ".NET" Java >}}

{{% codetab %}}

```javascript
// Do this!!
```

{{% /codetab %}}

{{% codetab %}}

Expand Down Expand Up @@ -285,7 +316,14 @@ Failure to follow this rule could result in undefined behavior. Any background p

For example, instead of this:

{{< tabs ".NET" Java >}}
{{< tabs JavaScript ".NET" Java >}}

{{% codetab %}}

```javascript
// DON'T DO THIS!
```
{{% /codetab %}}

{{% codetab %}}

Expand All @@ -312,7 +350,15 @@ ctx.createTimer(Duration.ofSeconds(5)).await();

Do this:

{{< tabs ".NET" Java >}}
{{< tabs JavaScript ".NET" Java >}}

{{% codetab %}}

```javascript
// Do this!!
```

{{% /codetab %}}

{{% codetab %}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,6 @@ Learn more about [different types of workflow patterns]({{< ref workflow-pattern

The Dapr Workflow _authoring SDKs_ are language-specific SDKs that contain types and functions to implement workflow logic. The workflow logic lives in your application and is orchestrated by the Dapr Workflow engine running in the Dapr sidecar via a gRPC stream.

### Supported SDKs
hhunter-ms marked this conversation as resolved.
Show resolved Hide resolved

You can use the following SDKs to author a workflow.

| Language stack | Package |
| - | - |
| Python | [dapr-ext-workflow](https://github.com/dapr/python-sdk/tree/master/ext/dapr-ext-workflow) |
| .NET | [Dapr.Workflow](https://www.nuget.org/profiles/dapr.io) |
| Java | [io.dapr.workflows](https://dapr.github.io/java-sdk/io/dapr/workflows/package-summary.html) |

## Try out workflows

### Quickstarts and tutorials
Expand All @@ -93,18 +83,16 @@ Want to put workflows to the test? Walk through the following quickstart and tut
| ------------------- | ----------- |
| [Workflow quickstart]({{< ref workflow-quickstart.md >}}) | Run a workflow application with four workflow activities to see Dapr Workflow in action |
| [Workflow Python SDK example](https://github.com/dapr/python-sdk/tree/master/examples/demo_workflow) | Learn how to create a Dapr Workflow and invoke it using the Python `DaprClient` package. |
| [Workflow JavaScript SDK example](todo) | Learn how to create a Dapr Workflow and invoke it using the JavaScript `todo` package. |
hhunter-ms marked this conversation as resolved.
Show resolved Hide resolved
| [Workflow .NET SDK example](https://github.com/dapr/dotnet-sdk/tree/master/examples/Workflow) | Learn how to create a Dapr Workflow and invoke it using ASP.NET Core web APIs. |
| [Workflow Java SDK example](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/workflows) | Learn how to create a Dapr Workflow and invoke it using the Java `io.dapr.workflows` package. |


### Start using workflows directly in your app

Want to skip the quickstarts? Not a problem. You can try out the workflow building block directly in your application. After [Dapr is installed]({{< ref install-dapr-cli.md >}}), you can begin using workflows, starting with [how to author a workflow]({{< ref howto-author-workflow.md >}}).

## Limitations

With Dapr Workflow in beta stage comes the following limitation(s):

- **State stores:** For the {{% dapr-latest-version cli="true" %}} beta release of Dapr Workflow, using the NoSQL databases as a state store results in limitations around storing internal states. For example, CosmosDB has a maximum single operation item limit of only 100 states in a single request.

- **Horizontal scaling:** For the {{% dapr-latest-version cli="true" %}} beta release of Dapr Workflow, if you scale out Dapr sidecars or your application pods to more than 2, then the concurrency of the workflow execution drops. It is recommended to test with 1 or 2 instances, and no more than 2.
Expand All @@ -123,6 +111,7 @@ Watch [this video for an overview on Dapr Workflow](https://youtu.be/s1p9MNl4VGo

- [Workflow API reference]({{< ref workflow_api.md >}})
- Try out the full SDK examples:
- [.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)
- [JavaScript example](todo)
- [.NET example](https://github.com/dapr/dotnet-sdk/tree/master/examples/Workflow)
- [Java example](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/workflows)
Loading
Loading