From f28d3523e700c385a8c9e3eeca5949d64f47fb1e Mon Sep 17 00:00:00 2001 From: gardusig Date: Thu, 23 Mar 2023 06:50:24 -0300 Subject: [PATCH 1/8] Updated README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d9ce64c..cbb23802 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ using Conductor.Client.Authentication; var configuration = new Configuration() { BasePath = basePath, - AuthenticationSettings = new OrkesAuthenticationSettings(keyId, keySecret) + AuthenticationSettings = new OrkesAuthenticationSettings("keyId", "keySecret") }; var workflowClient = configuration.GetClient(); From 80c49b1bd7b745624b0d39e35603133abf2872cf Mon Sep 17 00:00:00 2001 From: gardusig Date: Thu, 23 Mar 2023 13:24:26 -0300 Subject: [PATCH 2/8] Improved dependency injection with alternative usages --- .../DependencyInjectionExtensions.cs | 13 ++++++++ Conductor/Client/Worker/WorkflowTaskHost.cs | 32 +++++++++++++++++++ .../Client/Worker/WorkflowTaskService.cs | 9 ++---- Tests/Util/WorkerUtil.cs | 29 +++++++---------- docs/readme/workers.md | 4 +-- 5 files changed, 62 insertions(+), 25 deletions(-) create mode 100644 Conductor/Client/Worker/WorkflowTaskHost.cs rename Tests/Worker/WorkerService.cs => Conductor/Client/Worker/WorkflowTaskService.cs (76%) diff --git a/Conductor/Client/Extensions/DependencyInjectionExtensions.cs b/Conductor/Client/Extensions/DependencyInjectionExtensions.cs index 004746a9..5a18a243 100644 --- a/Conductor/Client/Extensions/DependencyInjectionExtensions.cs +++ b/Conductor/Client/Extensions/DependencyInjectionExtensions.cs @@ -16,6 +16,13 @@ public static IServiceCollection AddConductorWorkflowTask(this IServiceCollec return services; } + public static IServiceCollection AddConductorWorkflowTask(this IServiceCollection services, T worker) where T : IWorkflowTask + { + services.AddTransient(typeof(IWorkflowTask), typeof(T)); + services.AddTransient(typeof(T)); + return services; + } + public static IServiceCollection AddConductorWorker(this IServiceCollection services, Configuration configuration = null, Action configureHttpClient = null) { services.AddHttpClient(); @@ -35,5 +42,11 @@ public static IServiceCollection WithHostedService(this IServiceCollection se services.AddHostedService(); return services; } + + public static IServiceCollection WithHostedService(this IServiceCollection services) + { + services.AddHostedService(); + return services; + } } } diff --git a/Conductor/Client/Worker/WorkflowTaskHost.cs b/Conductor/Client/Worker/WorkflowTaskHost.cs new file mode 100644 index 00000000..8c230cc3 --- /dev/null +++ b/Conductor/Client/Worker/WorkflowTaskHost.cs @@ -0,0 +1,32 @@ +using Conductor.Client.Extensions; +using Conductor.Client.Interfaces; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace Conductor.Client.Worker +{ + public static class WorkflowTaskHost + { + public static IHost CreateWorkerHost(Configuration configuration, params T[] workers) where T : IWorkflowTask + { + return new HostBuilder() + .ConfigureServices( + (ctx, services) => + { + services.AddConductorWorker(configuration); + foreach (var worker in workers) + { + services.AddConductorWorkflowTask(worker); + } + services.WithHostedService(); + } + ).ConfigureLogging( + logging => + { + logging.SetMinimumLevel(LogLevel.Debug); + logging.AddConsole(); + } + ).Build(); + } + } +} \ No newline at end of file diff --git a/Tests/Worker/WorkerService.cs b/Conductor/Client/Worker/WorkflowTaskService.cs similarity index 76% rename from Tests/Worker/WorkerService.cs rename to Conductor/Client/Worker/WorkflowTaskService.cs index e057cb3e..50155432 100644 --- a/Tests/Worker/WorkerService.cs +++ b/Conductor/Client/Worker/WorkflowTaskService.cs @@ -3,17 +3,14 @@ using System.Threading; using System.Collections.Generic; -namespace Tests.Worker +namespace Conductor.Client.Worker { - public class WorkerService : BackgroundService + public class WorkflowTaskService : BackgroundService { private readonly IWorkflowTaskCoordinator _workflowTaskCoordinator; private readonly IEnumerable _workers; - public WorkerService( - IWorkflowTaskCoordinator workflowTaskCoordinator, - IEnumerable workers - ) + public WorkflowTaskService(IWorkflowTaskCoordinator workflowTaskCoordinator, IEnumerable workers) { _workflowTaskCoordinator = workflowTaskCoordinator; _workers = workers; diff --git a/Tests/Util/WorkerUtil.cs b/Tests/Util/WorkerUtil.cs index 3c0a18fe..547a18bc 100644 --- a/Tests/Util/WorkerUtil.cs +++ b/Tests/Util/WorkerUtil.cs @@ -1,5 +1,4 @@ -using Conductor.Client.Extensions; -using Microsoft.Extensions.Logging; +using Conductor.Client.Worker; using Microsoft.Extensions.Hosting; using Tests.Worker; @@ -7,23 +6,19 @@ namespace Tests.Util { public class WorkerUtil { + private static IHost _host = null; + + static WorkerUtil() + { + _host = WorkflowTaskHost.CreateWorkerHost( + ApiUtil.GetConfiguration(), + new SimpleWorker() + ); + } + public static IHost GetWorkerHost() { - return new HostBuilder() - .ConfigureServices( - (ctx, services) => - { - services.AddConductorWorker(ApiUtil.GetConfiguration()); - services.AddConductorWorkflowTask(); - services.WithHostedService(); - } - ).ConfigureLogging( - logging => - { - logging.SetMinimumLevel(LogLevel.Debug); - logging.AddConsole(); - } - ).Build(); + return _host; } } } \ No newline at end of file diff --git a/docs/readme/workers.md b/docs/readme/workers.md index 9127ba6d..646154cf 100644 --- a/docs/readme/workers.md +++ b/docs/readme/workers.md @@ -39,13 +39,13 @@ public class SimpleWorker : IWorkflowTask `TaskRunner` interface is used to start the workers, which takes care of polling server for the work, executing worker code and updating the results back to the server. ```csharp -private IHost GetWorkerHost() +private IHost GetWorkerHost(Configuration configuration) { return new HostBuilder() .ConfigureServices( (ctx, services) => { - services.AddConductorWorker(ApiUtil.GetConfiguration()); + services.AddConductorWorker(configuration); services.AddConductorWorkflowTask(); services.WithHostedService(); } From 34a778b3a557e8025afae50817212e9896606217 Mon Sep 17 00:00:00 2001 From: gardusig Date: Thu, 23 Mar 2023 13:35:27 -0300 Subject: [PATCH 3/8] Reduced load for worker tests --- Tests/Worker/WorkerTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Worker/WorkerTests.cs b/Tests/Worker/WorkerTests.cs index bff1a056..36c76aca 100644 --- a/Tests/Worker/WorkerTests.cs +++ b/Tests/Worker/WorkerTests.cs @@ -33,8 +33,8 @@ public async System.Threading.Tasks.Task TestWorkflowAsyncExecution() { ConductorWorkflow workflow = GetConductorWorkflow(); _workflowExecutor.RegisterWorkflow(workflow, true); - var workflowIdList = await StartWorkflows(workflow, quantity: 64); - await ExecuteWorkflowTasks(TimeSpan.FromSeconds(16)); + var workflowIdList = await StartWorkflows(workflow, quantity: 60); + await ExecuteWorkflowTasks(TimeSpan.FromSeconds(20)); await ValidateWorkflowCompletion(workflowIdList.ToArray()); } From c3629909e1fa9fa6929f044ed49171f69f45d84d Mon Sep 17 00:00:00 2001 From: gardusig Date: Thu, 23 Mar 2023 13:40:09 -0300 Subject: [PATCH 4/8] Updated client timeout --- Tests/Util/ApiUtil.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Util/ApiUtil.cs b/Tests/Util/ApiUtil.cs index 5704a80b..759b6d66 100644 --- a/Tests/Util/ApiUtil.cs +++ b/Tests/Util/ApiUtil.cs @@ -19,7 +19,7 @@ static ApiUtil() { _configuration = new Configuration() { - Timeout = 30000, + Timeout = 10000, BasePath = GetEnvironmentVariable(ENV_ROOT_URI), AuthenticationSettings = new OrkesAuthenticationSettings( GetEnvironmentVariable(ENV_KEY_ID), From 0f7525f8ebe63cf6c943cb2fe4b7136330d08a11 Mon Sep 17 00:00:00 2001 From: gardusig Date: Thu, 23 Mar 2023 13:43:10 -0300 Subject: [PATCH 5/8] Revert worker test load decrease --- Tests/Util/ApiUtil.cs | 2 +- Tests/Worker/WorkerTests.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Util/ApiUtil.cs b/Tests/Util/ApiUtil.cs index 759b6d66..dd8c8139 100644 --- a/Tests/Util/ApiUtil.cs +++ b/Tests/Util/ApiUtil.cs @@ -19,7 +19,7 @@ static ApiUtil() { _configuration = new Configuration() { - Timeout = 10000, + Timeout = 7500, BasePath = GetEnvironmentVariable(ENV_ROOT_URI), AuthenticationSettings = new OrkesAuthenticationSettings( GetEnvironmentVariable(ENV_KEY_ID), diff --git a/Tests/Worker/WorkerTests.cs b/Tests/Worker/WorkerTests.cs index 36c76aca..bff1a056 100644 --- a/Tests/Worker/WorkerTests.cs +++ b/Tests/Worker/WorkerTests.cs @@ -33,8 +33,8 @@ public async System.Threading.Tasks.Task TestWorkflowAsyncExecution() { ConductorWorkflow workflow = GetConductorWorkflow(); _workflowExecutor.RegisterWorkflow(workflow, true); - var workflowIdList = await StartWorkflows(workflow, quantity: 60); - await ExecuteWorkflowTasks(TimeSpan.FromSeconds(20)); + var workflowIdList = await StartWorkflows(workflow, quantity: 64); + await ExecuteWorkflowTasks(TimeSpan.FromSeconds(16)); await ValidateWorkflowCompletion(workflowIdList.ToArray()); } From d9dc7e6f97fdbb8d2ff05daccc5017bfc8ba732d Mon Sep 17 00:00:00 2001 From: gardusig Date: Thu, 23 Mar 2023 14:48:16 -0300 Subject: [PATCH 6/8] Updated worker docs --- docs/readme/workers.md | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/docs/readme/workers.md b/docs/readme/workers.md index 646154cf..a672dc13 100644 --- a/docs/readme/workers.md +++ b/docs/readme/workers.md @@ -36,29 +36,16 @@ public class SimpleWorker : IWorkflowTask ``` ## Starting Workers -`TaskRunner` interface is used to start the workers, which takes care of polling server for the work, executing worker code and updating the results back to the server. +You can use `WorkflowTaskHost` to create a worker host, it requires a configuration object and then you can add your workers. ```csharp -private IHost GetWorkerHost(Configuration configuration) -{ - return new HostBuilder() - .ConfigureServices( - (ctx, services) => - { - services.AddConductorWorker(configuration); - services.AddConductorWorkflowTask(); - services.WithHostedService(); - } - ).ConfigureLogging( - logging => - { - logging.SetMinimumLevel(LogLevel.Debug); - logging.AddConsole(); - } - ).Build(); -} +using Conductor.Client.Worker; +using System; +using System.Threading.Thread; -GetWorkerHost().RunAsync(); +var host = WorkflowTaskHost.CreateWorkerHost(configuration, new SimpleWorker()); +await host.startAsync(); +Thread.Sleep(TimeSpan.FromSeconds(100)); ``` Check out our [integration tests](https://github.com/conductor-sdk/conductor-csharp/blob/92c7580156a89322717c94aeaea9e5201fe577eb/Tests/Worker/WorkerTests.cs#L37) for more examples From 839501dcfa716b74990dec919b1f9232446ba881 Mon Sep 17 00:00:00 2001 From: gardusig Date: Thu, 23 Mar 2023 14:56:21 -0300 Subject: [PATCH 7/8] Updated documentation --- docs/readme/executor.md | 1 - docs/readme/workers.md | 2 +- docs/readme/workflow.md | 3 --- 3 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 docs/readme/executor.md diff --git a/docs/readme/executor.md b/docs/readme/executor.md deleted file mode 100644 index bc4e2a68..00000000 --- a/docs/readme/executor.md +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/docs/readme/workers.md b/docs/readme/workers.md index a672dc13..ca3a3ca0 100644 --- a/docs/readme/workers.md +++ b/docs/readme/workers.md @@ -65,4 +65,4 @@ Worker SDK collects the following metrics: Metrics on client side supplements the one collected from server in identifying the network as well as client side issues. -### Next: [Create and Execute Workflows](/docs/readme/workflow.md) +### Next: [Create and Execute Workflows](https://github.com/conductor-sdk/conductor-csharp/blob/main/docs/readme/workflow.md) diff --git a/docs/readme/workflow.md b/docs/readme/workflow.md index 6d3f29ee..b56e73d1 100644 --- a/docs/readme/workflow.md +++ b/docs/readme/workflow.md @@ -29,9 +29,6 @@ workflowExecutor.RegisterWorkflow( String workflowId = workflowExecutor.StartWorkflow(conductorWorkflow); ``` -### Workflow Management APIs -See [Docs](/docs/readme/executor.md) for APIs to start, pause, resume, terminate, search and get workflow execution status. - ### More Examples You can find more examples at the following GitHub repository: From 67dfb331f8bce819c7821f804f962b4d043fdc33 Mon Sep 17 00:00:00 2001 From: gardusig Date: Thu, 23 Mar 2023 15:03:28 -0300 Subject: [PATCH 8/8] Added constructor for WorkflowExecutor and improved documentation --- Conductor/Executor/WorkflowExecutor.cs | 9 ++++++++- docs/readme/workflow.md | 19 +++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Conductor/Executor/WorkflowExecutor.cs b/Conductor/Executor/WorkflowExecutor.cs index 47f68044..e68730db 100644 --- a/Conductor/Executor/WorkflowExecutor.cs +++ b/Conductor/Executor/WorkflowExecutor.cs @@ -1,6 +1,7 @@ using Conductor.Api; -using Conductor.Definition; +using Conductor.Client; using Conductor.Client.Models; +using Conductor.Definition; using System.Collections.Generic; namespace Conductor.Executor @@ -10,6 +11,12 @@ public class WorkflowExecutor private WorkflowResourceApi _workflowClient; private MetadataResourceApi _metadataClient; + public WorkflowExecutor(Configuration configuration) + { + _workflowClient = configuration.GetClient(); + _metadataClient = configuration.GetClient(); + } + public WorkflowExecutor(WorkflowResourceApi workflowClient, MetadataResourceApi metadataClient) { _workflowClient = workflowClient; diff --git a/docs/readme/workflow.md b/docs/readme/workflow.md index b56e73d1..2f2d3cda 100644 --- a/docs/readme/workflow.md +++ b/docs/readme/workflow.md @@ -3,6 +3,10 @@ ## A simple two-step workflow ```csharp +using Conductor.Client; +using Conductor.Definition; +using Conductor.Executor; + ConductorWorkflow GetConductorWorkflow() { return new ConductorWorkflow() @@ -11,22 +15,17 @@ ConductorWorkflow GetConductorWorkflow() .WithOwner("developers@orkes.io") .WithTask(new SimpleTask("simple_task_2", "simple_task_1")) .WithTask(new SimpleTask("simple_task_1", "simple_task_2")); - -WorkflowExecutor GetWorkflowExecutor() -{ - return new WorkflowExecutor( - metadataClient: GetClient(), - workflowClient: GetClient() - ); } -ConductorWorkflow conductorWorkflow = GetConductorWorkflow(); -WorkflowExecutor workflowExecutor = GetWorkflowExecutor(); +var configuration = new Configuration(); + +var conductorWorkflow = GetConductorWorkflow(); +var workflowExecutor = new WorkflowExecutor(configuration); workflowExecutor.RegisterWorkflow( workflow: conductorWorkflow overwrite: true ); -String workflowId = workflowExecutor.StartWorkflow(conductorWorkflow); +var workflowId = workflowExecutor.StartWorkflow(conductorWorkflow); ``` ### More Examples