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

Add workflow quickstart for JS #989

Merged
merged 21 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3d9799f
use InvokeHttpClient in service invocation csharp sample
MregXN Nov 21, 2023
cb2075f
add dependency
MregXN Nov 21, 2023
5097d9a
retrigger to pass validation
MregXN Nov 21, 2023
0453824
use daprWorkflowClient
MregXN Dec 14, 2023
48842ed
Clarified the actor state operations performed and what subsequent ac…
WhitWaldo Dec 30, 2023
cea9916
Updated comment to reflect call out on Discord by Pundil
WhitWaldo Dec 30, 2023
0f93b1d
Updated comment to reflect call out on Discord by Pundil
WhitWaldo Dec 30, 2023
b6a1a5e
Merge remote-tracking branch 'origin/updated-actor-csharp-quickstart-…
WhitWaldo Dec 30, 2023
334b35a
Merge pull request #979 from paulyuk/release-1.13
paulyuk Feb 10, 2024
873eecb
Revert "Fix tests broken by timing change"
paulyuk Feb 10, 2024
cfc5de1
Merge pull request #983 from dapr/revert-979-release-1.13
paulyuk Feb 10, 2024
583e9b3
Merge pull request #902 from MregXN/use-daprclient
paulyuk Feb 11, 2024
d718efe
Merge pull request #961 from WhitWaldo/updated-actor-csharp-quickstar…
paulyuk Feb 11, 2024
a933afe
Merge pull request #959 from MregXN/remove-daprClient-for-workflow
paulyuk Feb 11, 2024
e0ec38b
bump go to 1.21
mikeee Feb 13, 2024
474c283
bump short timeouts
mikeee Feb 13, 2024
ec1e515
Merge pull request #986 from mikeee/bump-go-validation
paulyuk Feb 14, 2024
2d7b401
add quickstart for JS
kaibocai Feb 16, 2024
5cfcd0e
fix readme check
kaibocai Feb 20, 2024
9aecc35
minor refactory
kaibocai Feb 27, 2024
1b8a451
Merge branch 'release-1.13' into kaibocai/add-js-quickstart
paulyuk Feb 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/env/global.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DAPR_CLI_VERSION: 1.12.0
DAPR_RUNTIME_VERSION: 1.13.0-rc.2
DAPR_RUNTIME_VERSION: 1.12.0
DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v${DAPR_CLI_VERSION}/install/
DAPR_DEFAULT_IMAGE_REGISTRY: ghcr
MACOS_PYTHON_VERSION: 3.10
19 changes: 10 additions & 9 deletions .github/workflows/validate_go_quickstarts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ jobs:
env:
DAPR_DEFAULT_IMAGE_REGISTRY: GHCR
DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/master/install
GOVER: 1.18
GOVER: 1.21
KUBERNETES_VERSION: v1.21.1
KIND_VERSION: v0.11.0
KIND_IMAGE_SHA: sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6
PODMAN_VERSION: 4.4.4
strategy:
matrix:
matrix:
os: [ubuntu-latest]
fail-fast: false
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Check out code
uses: actions/checkout@v4
- name: Load environment variables
uses: artursouza/export-env-action@v2
with:
envFile: './.github/env/global.env'
expand: 'true'
envFile: "./.github/env/global.env"
expand: "true"
- name: Install podman - MacOS
timeout-minutes: 15
if: matrix.os == 'macos-latest'
Expand All @@ -76,15 +76,15 @@ jobs:
sudo ln -s $(which podman) /usr/local/bin/docker
sudo ln -s $(which podman-compose) /usr/local/bin/docker-compose
- name: Set up Go ${{ env.GOVER }}
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: ${{ env.GOVER }}
- name: Set up Dapr CLI - Mac/Linux
if: matrix.os != 'windows-latest'
run: wget -q ${{ env.DAPR_INSTALL_URL }}/install.sh -O - | /bin/bash -s ${{ env.DAPR_CLI_VERSION }}
- name: Set up Dapr CLI - Windows
if: matrix.os == 'windows-latest'
run: powershell -Command "\$$script=iwr -useb ${{ env.DAPR_INSTALL_URL }}/install.ps1; \$$block=[ScriptBlock]::Create(\$$script); invoke-command -ScriptBlock \$$block -ArgumentList ${{ env.DAPR_CLI_VERSION }}"
run: powershell -Command "\$$script=iwr -useb ${{ env.DAPR_INSTALL_URL }}/install.ps1; \$$block=[ScriptBlock]::Create(\$$script); invoke-command -ScriptBlock \$$block -ArgumentList ${{ env.DAPR_CLI_VERSION }}"
- name: Install Dapr
run: |
export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -115,4 +115,5 @@ jobs:
done
- name: Linkcheck README.md
run: |
make validate
make validate

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ release.properties
mvnw
packages
**/__pycache__/
**/dist/

# IDE generated files and directories
*.iml
Expand Down
11 changes: 7 additions & 4 deletions actors/csharp/sdk/service/SmokeDetectorActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected override Task OnActivateAsync()
/// </summary>
protected override Task OnDeactivateAsync()
{
// Provides Opportunity to perform optional cleanup.
// Provides opportunity to perform optional cleanup.
Console.WriteLine($"Deactivating actor id: {Id}");
return Task.CompletedTask;
}
Expand All @@ -47,9 +47,12 @@ protected override Task OnDeactivateAsync()
/// <param name="data">the user-defined MyData which will be stored into state store as "device_data" state</param>
public async Task<string> SetDataAsync(SmartDeviceData data)
{
// Data is saved to configured state store *implicitly* after each method execution by Actor's runtime.
// Data can also be saved *explicitly* by calling this.StateManager.SaveStateAsync();
// State to be saved must be DataContract serializable.
// This set state action can happen along other state changing operations in each actor method and those changes will be maintained
// in a local cache to be committed as a single transaction to the backing store when the method has completed. As such, there is
// no need to (and in fact makes your code less transactional) call `this.StateManager.SaveStateAsync()` as it will be automatically
// invoked by the actor runtime following the conclusion of this method as part of the internal `OnPostActorMethodAsyncInternal` method.

// Note also that all saved state must be DataContract serializable.
await StateManager.SetStateAsync<SmartDeviceData>(
deviceDataKey,
data);
Expand Down
1 change: 1 addition & 0 deletions bindings/components/binding-cron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: cron
namespace: quickstarts
spec:
type: bindings.cron
version: v1
Expand Down
1 change: 1 addition & 0 deletions bindings/components/binding-postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: sqldb
namespace: quickstarts
spec:
type: bindings.postgres
version: v1
Expand Down
4 changes: 2 additions & 2 deletions pub_sub/go/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ expected_stderr_lines:
output_match_mode: substring
match_order: none
background: true
sleep: 15
timeout_seconds: 30
sleep: 30
timeout_seconds: 60
-->

```bash
Expand Down
4 changes: 2 additions & 2 deletions pub_sub/go/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ expected_stderr_lines:
output_match_mode: substring
match_order: none
background: true
sleep: 15
timeout_seconds: 30
sleep: 30
timeout_seconds: 60
-->

```bash
Expand Down
2 changes: 1 addition & 1 deletion secrets_management/go/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ dapr run --app-id order-processor --resources-path ../../../components/ -- go ru

```bash
dapr stop --app-id order-processor
```
```
16 changes: 7 additions & 9 deletions service_invocation/csharp/http/checkout/Program.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using Dapr.Client;

var baseURL = (Environment.GetEnvironmentVariable("BASE_URL") ?? "http://localhost") + ":" + (Environment.GetEnvironmentVariable("DAPR_HTTP_PORT") ?? "3500");

var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
// Adding app id as part of the header
client.DefaultRequestHeaders.Add("dapr-app-id", "order-processor");
var client = DaprClient.CreateInvokeHttpClient(appId: "order-processor");

for (int i = 1; i <= 20; i++) {
var order = new Order(i);
var orderJson = JsonSerializer.Serialize<Order>(order);
var content = new StringContent(orderJson, Encoding.UTF8, "application/json");

var cts = new CancellationTokenSource();
Console.CancelKeyPress += (object? sender, ConsoleCancelEventArgs e) => cts.Cancel();

// Invoking a service
var response = await client.PostAsync($"{baseURL}/orders", content);
var response = await client.PostAsJsonAsync("/orders", order, cts.Token);

Console.WriteLine("Order passed: " + order);

await Task.Delay(TimeSpan.FromSeconds(1));
Expand Down
7 changes: 6 additions & 1 deletion service_invocation/csharp/http/checkout/checkout.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
<ItemGroup>
<PackageReference Include="Dapr.Client" Version="1.12.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions service_invocation/go/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ expected_stderr_lines:
output_match_mode: substring
match_order: none
background: true
sleep: 15
timeout_seconds: 30
sleep: 30
timeout_seconds: 60
-->

```bash
Expand Down
2 changes: 1 addition & 1 deletion state_management/csharp/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ sleep: 15
cd ./order-processor
dapr run --app-id order-processor --resources-path ../../../resources/ -- dotnet run
```
<!-- END_STEP -->

2. Stop and clean up application processes

dapr stop --app-id order-processor
<!-- END_STEP -->
4 changes: 1 addition & 3 deletions state_management/csharp/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ You're up and running! Both Dapr and your app logs will appear here.
== APP == Getting Order: Order { orderId = 3 }
== APP == Deleting Order: Order { orderId = 3 }
```
<!-- END_STEP -->

2. Stop and clean up application processes

```bash
dapr stop --app-id order-processor
```
<!-- END_STEP -->
5 changes: 2 additions & 3 deletions state_management/go/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ You're up and running! Both Dapr and your app logs will appear here.
== APP == Retrieved Order: "{\"orderId\":3}"
== APP == 2023/09/24 23:31:27 Deleted Order: {"orderId":3}
```
<!-- END_STEP -->

2. Stop and clean up application processes
```bash
dapr stop --app-id order-processor
```

<!-- END_STEP -->
5 changes: 2 additions & 3 deletions state_management/go/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ You're up and running! Both Dapr and your app logs will appear here.
== APP - order-processor == Retrieved Order: {"orderId":2}
== APP - order-processor == Deleted Order: {"orderId":2}
```
<!-- END_STEP -->

2. Stop and clean up application processes
```bash
dapr stop --app-id order-processor
```

<!-- END_STEP -->
3 changes: 1 addition & 2 deletions state_management/javascript/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ sleep: 60
```bash
dapr run --app-id order-processor --resources-path ../../../resources/ -- npm start
```
<!-- END_STEP -->

2. Stop and cleanup the process

```bash
dapr stop --app-id order-processor
```

<!-- END_STEP -->
29 changes: 12 additions & 17 deletions workflows/csharp/sdk/order-processor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@

using var daprClient = new DaprClientBuilder().Build();

// NOTE: WorkflowEngineClient will be replaced with a richer version of DaprClient
// in a subsequent SDK release. This is a temporary workaround.
WorkflowEngineClient workflowClient = host.Services.GetRequiredService<WorkflowEngineClient>();
DaprWorkflowClient workflowClient = host.Services.GetRequiredService<DaprWorkflowClient>();

// Generate a unique ID for the workflow
string orderId = Guid.NewGuid().ToString()[..8];
Expand All @@ -51,28 +49,25 @@
// Start the workflow
Console.WriteLine("Starting workflow {0} purchasing {1} {2}", orderId, ammountToPurchase, itemToPurchase);

await daprClient.StartWorkflowAsync(
workflowComponent: DaprWorkflowComponent,
workflowName: nameof(OrderProcessingWorkflow),
input: orderInfo,
instanceId: orderId);
await workflowClient.ScheduleNewWorkflowAsync(
name: nameof(OrderProcessingWorkflow),
instanceId: orderId,
input: orderInfo);

// Wait for the workflow to start and confirm the input
GetWorkflowResponse state = await daprClient.WaitForWorkflowStartAsync(
instanceId: orderId,
workflowComponent: DaprWorkflowComponent);
WorkflowState state = await workflowClient.WaitForWorkflowStartAsync(
instanceId: orderId);

Console.WriteLine("Your workflow has started. Here is the status of the workflow: {0}", state.RuntimeStatus);
Console.WriteLine("Your workflow has started. Here is the status of the workflow: {0}", Enum.GetName(typeof(WorkflowRuntimeStatus), state.RuntimeStatus));

// Wait for the workflow to complete
state = await daprClient.WaitForWorkflowCompletionAsync(
instanceId: orderId,
workflowComponent: DaprWorkflowComponent);
state = await workflowClient.WaitForWorkflowCompletionAsync(
instanceId: orderId);

Console.WriteLine("Workflow Status: {0}", state.RuntimeStatus);
Console.WriteLine("Workflow Status: {0}", Enum.GetName(typeof(WorkflowRuntimeStatus), state.RuntimeStatus));

void RestockInventory(string itemToPurchase)
{
daprClient.SaveStateAsync<OrderPayload>(StoreName, itemToPurchase, new OrderPayload(Name: itemToPurchase, TotalCost: 15000, Quantity: 100));
daprClient.SaveStateAsync<OrderPayload>(StoreName, itemToPurchase, new OrderPayload(Name: itemToPurchase, TotalCost: 15000, Quantity: 100));
return;
}