diff --git a/Microsoft.DurableTask.sln b/Microsoft.DurableTask.sln index 53f5f4bcf..0ca1cad17 100644 --- a/Microsoft.DurableTask.sln +++ b/Microsoft.DurableTask.sln @@ -51,8 +51,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp", "samples\Conso EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFxConsoleApp", "samples\NetFxConsoleApp\NetFxConsoleApp.csproj", "{8A0156E6-F033-49AB-AB0C-6698CE1DB24F}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebAPI", "samples\WebAPI\WebAPI.csproj", "{21AF0D71-6D32-483F-B6E8-3B28EE432560}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "src\Shared\Shared.csproj", "{57A4C812-B0D9-49E9-9EBE-7E94D3D78ED7}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "misc", "misc\misc.csproj", "{1E135970-60CF-470A-9270-4560BFA0A7DF}" @@ -175,10 +173,6 @@ Global {8A0156E6-F033-49AB-AB0C-6698CE1DB24F}.Debug|Any CPU.Build.0 = Debug|Any CPU {8A0156E6-F033-49AB-AB0C-6698CE1DB24F}.Release|Any CPU.ActiveCfg = Release|Any CPU {8A0156E6-F033-49AB-AB0C-6698CE1DB24F}.Release|Any CPU.Build.0 = Release|Any CPU - {21AF0D71-6D32-483F-B6E8-3B28EE432560}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {21AF0D71-6D32-483F-B6E8-3B28EE432560}.Debug|Any CPU.Build.0 = Debug|Any CPU - {21AF0D71-6D32-483F-B6E8-3B28EE432560}.Release|Any CPU.ActiveCfg = Release|Any CPU - {21AF0D71-6D32-483F-B6E8-3B28EE432560}.Release|Any CPU.Build.0 = Release|Any CPU {57A4C812-B0D9-49E9-9EBE-7E94D3D78ED7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {57A4C812-B0D9-49E9-9EBE-7E94D3D78ED7}.Debug|Any CPU.Build.0 = Debug|Any CPU {57A4C812-B0D9-49E9-9EBE-7E94D3D78ED7}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -297,7 +291,6 @@ Global {848FC5BD-4A99-4A0D-9099-9597700AA7BC} = {EFF7632B-821E-4CFC-B4A0-ED4B24296B17} {93ED401F-5AD2-47B6-B4CA-BA791D8B82B2} = {EFF7632B-821E-4CFC-B4A0-ED4B24296B17} {8A0156E6-F033-49AB-AB0C-6698CE1DB24F} = {EFF7632B-821E-4CFC-B4A0-ED4B24296B17} - {21AF0D71-6D32-483F-B6E8-3B28EE432560} = {EFF7632B-821E-4CFC-B4A0-ED4B24296B17} {57A4C812-B0D9-49E9-9EBE-7E94D3D78ED7} = {8AFC9781-F6F1-4696-BB4A-9ED7CA9D612B} {505F6151-6E36-4E0A-A740-14751B8A9397} = {1C217BB2-CE16-41CC-9D47-0FC0DB60BDB3} {93E3B973-0FC4-4241-B7BB-064FB538FB50} = {5AD837BC-78F3-4543-8AA3-DF74D0DF94C0} diff --git a/samples/WebAPI/.dockerignore b/samples/WebAPI/.dockerignore deleted file mode 100644 index b6baed846..000000000 --- a/samples/WebAPI/.dockerignore +++ /dev/null @@ -1,27 +0,0 @@ -.vscode -tools -.dotnet -Dockerfile -.git/ -.vs/ - -# User-specific files -*.suo -*.user -*.userosscache -*.sln.docstates - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ - -# .env file contains default environment variables for docker -.env diff --git a/samples/WebAPI/Controllers/OrderProcessingController.cs b/samples/WebAPI/Controllers/OrderProcessingController.cs deleted file mode 100644 index 314e91f5c..000000000 --- a/samples/WebAPI/Controllers/OrderProcessingController.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using Microsoft.AspNetCore.Mvc; -using Microsoft.DurableTask; -using Microsoft.DurableTask.Client; -using WebAPI.Models; - -namespace WebAPI.Controllers; - -[Route("orders")] -[ApiController] -public class OrderProcessingController : ControllerBase -{ - readonly DurableTaskClient durableTaskClient; - - public OrderProcessingController(DurableTaskClient durableTaskClient) - { - this.durableTaskClient = durableTaskClient; - } - - // HTTPie command: - // http POST http://localhost:8080/orders/new Item=catfood Quantity=5 Price=600 - [HttpPost("new")] - public async Task CreateOrder([FromBody] OrderInfo orderInfo) - { - if (orderInfo == null || orderInfo.Item == null) - { - return this.BadRequest(new { error = "No item information was included in the order" }); - } - - // Generate an order ID and start the order processing workflow orchestration - string orderId = $"{orderInfo.Item}-{Guid.NewGuid().ToString()[..4]}"; - await this.durableTaskClient.ScheduleNewProcessOrderOrchestratorInstanceAsync( - orderInfo, new StartOrchestrationOptions() { InstanceId = orderId }); - - // Return 202 with a link to the GetOrderStatus API - return this.AcceptedAtAction( - actionName: nameof(GetOrderStatus), - controllerName: null, - routeValues: new { orderId }, - value: new { orderId }); - } - - [HttpGet("{orderId}")] - public async Task GetOrderStatus(string orderId) - { - OrchestrationMetadata? metadata = await this.durableTaskClient.GetInstancesAsync( - instanceId: orderId, - getInputsAndOutputs: true); - - // TODO: Include a link to the approval API - - return this.Ok(new - { - Found = metadata != null, - Metadata = metadata, - }); - } -} diff --git a/samples/WebAPI/Dockerfile b/samples/WebAPI/Dockerfile deleted file mode 100644 index 393026c78..000000000 --- a/samples/WebAPI/Dockerfile +++ /dev/null @@ -1,29 +0,0 @@ -#FROM mcr.microsoft.com/dotnet/sdk:5.0 as build -# -#WORKDIR /src -#COPY api/api.csproj . -#RUN dotnet restore -# -#COPY api/ . -#RUN dotnet publish -c Release -o /out -# -#FROM mcr.microsoft.com/dotnet/aspnet:5.0 -# -#WORKDIR /app -#COPY --from=build /out/ /app -# -#ENTRYPOINT ["dotnet", "/app/api.dll"] - -FROM mcr.microsoft.com/dotnet/sdk:6.0 as build - -COPY . /root -RUN cd /root/samples/WebAPI && dotnet restore -RUN cd /root/samples/WebAPI && dotnet publish -c Release -o /out - -FROM mcr.microsoft.com/dotnet/aspnet:6.0 - -WORKDIR /app -COPY --from=build /out/ /app - -EXPOSE 8080 -ENTRYPOINT ["dotnet", "/app/WebAPI.dll"] \ No newline at end of file diff --git a/samples/WebAPI/Models/ApprovalEvent.cs b/samples/WebAPI/Models/ApprovalEvent.cs deleted file mode 100644 index 02c165828..000000000 --- a/samples/WebAPI/Models/ApprovalEvent.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -namespace WebAPI.Models; - -public class ApprovalEvent -{ - public bool IsApproved { get; set; } - - public string? Approver { get; set; } -} diff --git a/samples/WebAPI/Models/OrderInfo.cs b/samples/WebAPI/Models/OrderInfo.cs deleted file mode 100644 index 2d90b2bd8..000000000 --- a/samples/WebAPI/Models/OrderInfo.cs +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -namespace WebAPI.Models; - -public record OrderInfo(string Item, int Quantity, double Price); diff --git a/samples/WebAPI/Models/OrderStatus.cs b/samples/WebAPI/Models/OrderStatus.cs deleted file mode 100644 index cd7cb4165..000000000 --- a/samples/WebAPI/Models/OrderStatus.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -namespace WebAPI.Models; - -public class OrderStatus -{ - public bool RequiresApproval { get; set; } - - public ApprovalEvent? Approval { get; set; } -} diff --git a/samples/WebAPI/Orchestrations/ChargeCustomerActivity.cs b/samples/WebAPI/Orchestrations/ChargeCustomerActivity.cs deleted file mode 100644 index 768d1b96b..000000000 --- a/samples/WebAPI/Orchestrations/ChargeCustomerActivity.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using Microsoft.DurableTask; -using WebAPI.Models; - -namespace WebAPI.Orchestrations; - -[DurableTask("ChargeCustomer")] -public class ChargeCustomerActivity : TaskActivity -{ - readonly ILogger logger; - - // Dependencies are injected from ASP.NET host service container - public ChargeCustomerActivity(ILogger logger) - { - this.logger = logger; - } - - public override async Task RunAsync(TaskActivityContext context, OrderInfo orderInfo) - { - this.logger.LogInformation( - "{instanceId}: Charging customer {price:C}'...", - context.InstanceId, - orderInfo?.Price ?? 0.0); - - await Task.Delay(TimeSpan.FromSeconds(3)); - return null; - } -} diff --git a/samples/WebAPI/Orchestrations/CheckInventoryActivity.cs b/samples/WebAPI/Orchestrations/CheckInventoryActivity.cs deleted file mode 100644 index 198575f48..000000000 --- a/samples/WebAPI/Orchestrations/CheckInventoryActivity.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using Microsoft.DurableTask; -using WebAPI.Models; - -namespace WebAPI.Orchestrations -{ - [DurableTask("CheckInventory")] - public class CheckInventoryActivity : TaskActivity - { - readonly ILogger logger; - - // Dependencies are injected from ASP.NET host service container - public CheckInventoryActivity(ILogger logger) - { - this.logger = logger; - } - - public override Task RunAsync(TaskActivityContext context, OrderInfo orderInfo) - { - if (orderInfo == null) - { - throw new ArgumentException("Failed to read order info!"); - } - - this.logger.LogInformation( - "{instanceId}: Checking inventory for '{item}'...found some!", - context.InstanceId, - orderInfo.Item); - return Task.FromResult(true); - } - } -} diff --git a/samples/WebAPI/Orchestrations/CreateShipmentActivity.cs b/samples/WebAPI/Orchestrations/CreateShipmentActivity.cs deleted file mode 100644 index e1cc8a7cd..000000000 --- a/samples/WebAPI/Orchestrations/CreateShipmentActivity.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using Microsoft.DurableTask; -using WebAPI.Models; - -namespace WebAPI.Orchestrations; - -[DurableTask("CreateShipment")] -public class CreateShipmentActivity : TaskActivity -{ - readonly ILogger logger; - - // Dependencies are injected from ASP.NET host service container - public CreateShipmentActivity(ILogger logger) - { - this.logger = logger; - } - - public override async Task RunAsync(TaskActivityContext context, OrderInfo orderInfo) - { - this.logger.LogInformation( - "{instanceId}: Shipping customer order of {quantity} {item}(s)...", - context.InstanceId, - orderInfo?.Quantity ?? 0, - orderInfo?.Item); - - await Task.Delay(TimeSpan.FromSeconds(3)); - return null; - } -} diff --git a/samples/WebAPI/Orchestrations/ProcessOrderOrchestrator.cs b/samples/WebAPI/Orchestrations/ProcessOrderOrchestrator.cs deleted file mode 100644 index 07b4f119d..000000000 --- a/samples/WebAPI/Orchestrations/ProcessOrderOrchestrator.cs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using Microsoft.DurableTask; -using WebAPI.Models; - -namespace WebAPI.Orchestrations; - -[DurableTask] -public class ProcessOrderOrchestrator : TaskOrchestrator -{ - public override async Task RunAsync(TaskOrchestrationContext context, OrderInfo orderInfo) - { - ArgumentNullException.ThrowIfNull(orderInfo); - - // Call the following activity operations in sequence. - OrderStatus orderStatus = new(); - if (await context.CallCheckInventoryAsync(orderInfo)) - { - // Orders over $1,000 require manual approval. We use a custom status - // value to communicate this back to the client application. - bool requiresApproval = orderInfo.Price > 1000.00; - context.SetCustomStatus(new { requiresApproval }); - - if (requiresApproval) - { - orderStatus.RequiresApproval = true; - - ApprovalEvent approvalEvent; - try - { - // Wait for the client application to send an approval event. - // Auto-reject if an approval isn't received in 10 seconds. - approvalEvent = await context.WaitForExternalEvent( - eventName: "Approve", - timeout: TimeSpan.FromSeconds(10)); - } - catch (TaskCanceledException) - { - approvalEvent = new ApprovalEvent { IsApproved = false }; - } - - orderStatus.Approval = approvalEvent; - if (!approvalEvent.IsApproved) - { - return orderStatus; - } - } - - await context.CallChargeCustomerAsync(orderInfo); - await context.CallCreateShipmentAsync(orderInfo); - - return orderStatus; - } - - return orderStatus; - } -} diff --git a/samples/WebAPI/Program.cs b/samples/WebAPI/Program.cs deleted file mode 100644 index 111413eef..000000000 --- a/samples/WebAPI/Program.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using System.Text.Json.Serialization; -using Microsoft.DurableTask; -using Microsoft.DurableTask.Client; -using Microsoft.DurableTask.Worker; - -WebApplicationBuilder builder = WebApplication.CreateBuilder(args); - -// Add all the generated tasks -builder.Services.AddDurableTaskWorker(builder => -{ - builder.AddTasks(r => r.AddAllGeneratedTasks()); - builder.UseGrpc(); -}); - -builder.Services.AddDurableTaskClient(b => b.UseGrpc()); - -// Configure the HTTP request pipeline. -builder.Services.AddControllers().AddJsonOptions(options => -{ - options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); - options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; -}); - -WebApplication app = builder.Build(); -app.MapControllers(); -app.Run("http://0.0.0.0:8080"); diff --git a/samples/WebAPI/Properties/launchSettings.json b/samples/WebAPI/Properties/launchSettings.json deleted file mode 100644 index e119b069f..000000000 --- a/samples/WebAPI/Properties/launchSettings.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:47697", - "sslPort": 44371 - } - }, - "profiles": { - "WebAPI": { - "commandName": "Project", - "launchBrowser": true, - "launchUrl": "weatherforecast", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development", - "DURABLETASK_SIDECAR_ADDRESS": "http://localhost:4001" - }, - "applicationUrl": "https://localhost:7217;http://localhost:5217", - "dotnetRunMessages": true - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "weatherforecast", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} \ No newline at end of file diff --git a/samples/WebAPI/WebAPI.csproj b/samples/WebAPI/WebAPI.csproj deleted file mode 100644 index 84680817d..000000000 --- a/samples/WebAPI/WebAPI.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - net6.0;net8.0;net10.0 - enable - enable - true - $(BaseIntermediateOutputPath)Generated - - - - - - - - - diff --git a/samples/WebAPI/appsettings.Development.json b/samples/WebAPI/appsettings.Development.json deleted file mode 100644 index 0c208ae91..000000000 --- a/samples/WebAPI/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/samples/WebAPI/appsettings.json b/samples/WebAPI/appsettings.json deleted file mode 100644 index 10f68b8c8..000000000 --- a/samples/WebAPI/appsettings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "AllowedHosts": "*" -} diff --git a/samples/WebAPI/demo-deployment.yaml b/samples/WebAPI/demo-deployment.yaml deleted file mode 100644 index d5d9bf6f2..000000000 --- a/samples/WebAPI/demo-deployment.yaml +++ /dev/null @@ -1,43 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: demo-webapi - labels: - app: demo-webapi -spec: - replicas: 1 - selector: - matchLabels: - app: demo-webapi - template: - metadata: - labels: - app: demo-webapi - spec: - containers: - - name: demo-webapi - image: cgillum/durabletask-samples-webapi:latest - ports: - - containerPort: 8080 - - name: durabletask-sidecar - image: cgillum/durabletask-sidecar:latest - ports: - - containerPort: 4001 - env: - - name: APPINSIGHTS_INSTRUMENTATIONKEY - value: c1b602ab-2591-4791-8729-c803e9f5d518 - args: ["start", "--backend", "Emulator"] ---- -apiVersion: v1 -kind: Service -metadata: - name: demo-webapi -spec: - type: LoadBalancer - ports: - - name: http - protocol: TCP - port: 8080 - targetPort: 8080 - selector: - app: demo-webapi \ No newline at end of file