Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hhunter-ms committed Feb 14, 2024
2 parents 164b3d9 + ec1e515 commit 273634a
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 47 deletions.
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
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
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
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;
}

0 comments on commit 273634a

Please sign in to comment.