-
Notifications
You must be signed in to change notification settings - Fork 373
Workflow Authoring: initial methods #981
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
Merged
Merged
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
47dea1d
Initial workflow sdk implementation
amulyavarote 1e649cc
Dapr Workflow initial methods for dotnet-sdk
amulyavarote 6dbbe26
Handled mistake in the workflow name
amulyavarote f69a314
Added common license header to .cs files
amulyavarote 266cefd
Changed namespace to Dapr.Workflow
amulyavarote 01c01e5
Addressed docs related review comments
amulyavarote 73b08a5
Reverted few changes to avoid compile time error
amulyavarote b832ab8
Examples changes
amulyavarote 2515d01
Added readonly dictionary
amulyavarote fc1ee56
Added .csproj to sln file with few minor comments
amulyavarote dd5a294
Change nuget dependency and update folder structure
tmacam 99285a9
Update Durable Task SDK version & simplify example
cgillum 38d2330
Merge pull request #1 from cgillum/cgillum/durabletask-v1.0.0-rc.1
tmacam 6d7f5ff
Addresses some PR comments.
tmacam 1bbaa0a
Addressing review comments.
tmacam 601f09e
Adding more documentation
tmacam b9c99cf
Replaces custom AddSingletonIfNotPresent with std. TryAddSingleton
tmacam f49b648
Renames AddWorkflowsToRegistry to AddActivitiesToRegistry to better m…
tmacam ad7ade2
Add cancelation token overload for WorkflowContext.WaitForExternalEve…
tmacam 509656b
Renaming AddWorkflowsAndActivitiesToRegistry
tmacam fb8589c
Defer launch URL and port to launchSettings.json
tmacam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| using Dapr.Workflow; | ||
|
|
||
| // The workflow host is a background service that connects to the sidecar over gRPC | ||
| WebApplicationBuilder builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| // Dapr workflows are registered as part of the service configuration | ||
| builder.Services.AddDaprWorkflow(options => | ||
| { | ||
| // Example of registering a "PlaceOrder" workflow function | ||
| options.RegisterWorkflow<string, string>("PlaceOrder", implementation: async (context, input) => | ||
| { | ||
| // In real life there are other steps related to placing an order, like reserving | ||
| // inventory and charging the customer credit card etc. But let's keep it simple ;) | ||
| return await context.CallActivityAsync<string>("ShipProduct", "Coffee Beans"); | ||
| }); | ||
|
|
||
| // Example of registering a "ShipProduct" workflow activity function | ||
| options.RegisterActivity<string, string>("ShipProduct", implementation: (context, input) => | ||
| { | ||
| return Task.FromResult($"We are shipping {input} to the customer using our hoard of drones!"); | ||
| }); | ||
| }); | ||
|
|
||
| WebApplication app = builder.Build(); | ||
|
|
||
| // POST starts new workflow instances | ||
| app.MapPost("/order", async (HttpContext context, WorkflowClient client) => | ||
| { | ||
| string id = Guid.NewGuid().ToString()[..8]; | ||
| await client.ScheduleNewWorkflowAsync("PlaceOrder", id); | ||
|
|
||
| // return an HTTP 202 and a Location header to be used for status query | ||
| return Results.AcceptedAtRoute("GetOrderEndpoint", new { id }); | ||
| }); | ||
|
|
||
| // GET fetches metadata for specific order workflow instances | ||
| app.MapGet("/order/{id}", async (string id, WorkflowClient client) => | ||
| { | ||
| WorkflowMetadata metadata = await client.GetWorkflowMetadataAsync(id, getInputsAndOutputs: true); | ||
| if (metadata.Exists) | ||
| { | ||
| return Results.Ok(metadata); | ||
| } | ||
| else | ||
| { | ||
| return Results.NotFound($"No workflow created for order with ID = '{id}' was found."); | ||
| } | ||
| }).WithName("GetOrderEndpoint"); | ||
|
|
||
| app.Run("http://0.0.0.0:10080"); | ||
|
tmacam marked this conversation as resolved.
Outdated
|
||
|
|
||
12 changes: 12 additions & 0 deletions
12
examples/Workflow/WorkflowWebApp/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
|
tmacam marked this conversation as resolved.
|
||
| "profiles": { | ||
| "OrderingWebApi": { | ||
| "commandName": "Project", | ||
| "launchBrowser": true, | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| }, | ||
| "applicationUrl": "https://localhost:10080;http://localhost:10080" | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\src\Dapr.Workflow\Dapr.Workflow.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFrameworks>net6</TargetFrameworks> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <LangVersion>latest</LangVersion> | ||
|
tmacam marked this conversation as resolved.
|
||
| </PropertyGroup> | ||
|
|
||
|
|
||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ### Create new order | ||
| POST http://localhost:8080/workflow | ||
| Content-Type: application/json | ||
|
|
||
| ### Query placeholder | ||
| GET http://localhost:8080/workflow/XXX |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <!-- NuGet configuration --> | ||
| <PropertyGroup> | ||
| <TargetFrameworks>netcoreapp3.1;net5;net6</TargetFrameworks> | ||
| <Nullable>enable</Nullable> | ||
| <PackageId>Dapr.Workflow</PackageId> | ||
| <Title>Dapr Workflow Authoring SDK</Title> | ||
| <Description>Dapr Workflow SDK for building workflows as code with Dapr</Description> | ||
| <VersionPrefix>0.1.0</VersionPrefix> | ||
| <VersionSuffix>alpha</VersionSuffix> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.DurableTask.Client.Grpc" Version="1.0.0-rc.1" /> | ||
| <PackageReference Include="Microsoft.DurableTask.Worker.Grpc" Version="1.0.0-rc.1" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Dapr.Client\Dapr.Client.csproj" /> | ||
| <ProjectReference Include="..\Dapr.AspNetCore\Dapr.AspNetCore.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // ------------------------------------------------------------------------ | ||
| // Copyright 2022 The Dapr Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // ------------------------------------------------------------------------ | ||
|
|
||
| namespace Dapr.Workflow | ||
| { | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.DurableTask; | ||
|
|
||
| /// <summary> | ||
| /// Defines properties and methods for task activity context objects. | ||
| /// </summary> | ||
| public class WorkflowActivityContext | ||
| { | ||
| readonly TaskActivityContext innerContext; | ||
|
|
||
| internal WorkflowActivityContext(TaskActivityContext innerContext) | ||
| { | ||
| this.innerContext = innerContext ?? throw new ArgumentNullException(nameof(innerContext)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the name of the activity. | ||
| /// </summary> | ||
| public TaskName Name => this.innerContext.Name; | ||
|
|
||
| /// <summary> | ||
| /// Gets the unique ID of the current workflow instance. | ||
| /// </summary> | ||
| public string InstanceId => this.innerContext.InstanceId; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.