From 042418991910a22ff772aedc113ac84792b736b8 Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Wed, 4 Dec 2024 10:13:17 -0300 Subject: [PATCH 01/12] In Orkes Conductor API when polling a workflow task maybe present without a name or task reference --- Conductor/Client/Models/WorkflowTask.cs | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/Conductor/Client/Models/WorkflowTask.cs b/Conductor/Client/Models/WorkflowTask.cs index d73bca7..d90d3c1 100644 --- a/Conductor/Client/Models/WorkflowTask.cs +++ b/Conductor/Client/Models/WorkflowTask.cs @@ -15,7 +15,6 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.IO; using System.Linq; using System.Runtime.Serialization; using System.Text; @@ -225,24 +224,8 @@ public enum WorkflowTaskTypeEnum /// workflowTaskType. public WorkflowTask(bool? asyncComplete = default(bool?), string caseExpression = default(string), string caseValueParam = default(string), Dictionary> decisionCases = default(Dictionary>), List defaultCase = default(List), List defaultExclusiveJoinTask = default(List), string description = default(string), string dynamicForkJoinTasksParam = default(string), string dynamicForkTasksInputParamName = default(string), string dynamicForkTasksParam = default(string), string dynamicTaskNameParam = default(string), string evaluatorType = default(string), string expression = default(string), List> forkTasks = default(List>), Dictionary inputParameters = default(Dictionary), List joinOn = default(List), string loopCondition = default(string), List loopOver = default(List), string name = default(string), bool? optional = default(bool?), bool? rateLimited = default(bool?), int? retryCount = default(int?), string scriptExpression = default(string), string sink = default(string), int? startDelay = default(int?), SubWorkflowParams subWorkflowParam = default(SubWorkflowParams), TaskDef taskDefinition = default(TaskDef), string taskReferenceName = default(string), string type = default(string), WorkflowTaskTypeEnum? workflowTaskType = default(WorkflowTaskTypeEnum?), Dictionary onStateChange = default(Dictionary)) { - // to ensure "name" is required (not null) - if (name == null) - { - throw new InvalidDataException("name is a required property for WorkflowTask and cannot be null"); - } - else - { - this.Name = name; - } - // to ensure "taskReferenceName" is required (not null) - if (taskReferenceName == null) - { - throw new InvalidDataException("taskReferenceName is a required property for WorkflowTask and cannot be null"); - } - else - { - this.TaskReferenceName = taskReferenceName; - } + this.TaskReferenceName = taskReferenceName; + this.Name = name; this.AsyncComplete = asyncComplete; this.CaseExpression = caseExpression; this.CaseValueParam = caseValueParam; From dcebe395ec4aebe4969e78220ae6afdcd78f47f9 Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Wed, 4 Dec 2024 10:14:03 -0300 Subject: [PATCH 02/12] Error message on error while getting token suggest checking the config --- Conductor/Client/Authentication/TokenHandler.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Conductor/Client/Authentication/TokenHandler.cs b/Conductor/Client/Authentication/TokenHandler.cs index f0579e1..e743e29 100644 --- a/Conductor/Client/Authentication/TokenHandler.cs +++ b/Conductor/Client/Authentication/TokenHandler.cs @@ -62,7 +62,15 @@ private string GetTokenFromServer(OrkesAuthenticationSettings authenticationSett { try { - return tokenClient.GenerateToken(tokenRequest)._token; + var token = tokenClient.GenerateToken(tokenRequest); + return token._token; + } + catch (ApiException e) + { + if (e.ErrorCode == 405 || e.ErrorCode == 404) + { + throw new Exception($"Error while getting authentication token. Is the config BasePath correct? {tokenClient.Configuration.BasePath}"); + } } catch (Exception e) { From ac3bf26dbbeb4567636d7040612efbfc688172b2 Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Wed, 4 Dec 2024 10:29:57 -0300 Subject: [PATCH 03/12] Moved Examples into csharp-examples project --- Conductor/conductor-csharp.csproj | 2 +- Tests/conductor-csharp.test.csproj | 3 ++- {Conductor => csharp-examples}/Examples/Copilot/Customer.cs | 0 .../Examples/Copilot/OpenAICopilot.cs | 0 {Conductor => csharp-examples}/Examples/DynamicWorkflow.cs | 0 {Conductor => csharp-examples}/Examples/ExampleConstant.cs | 0 {Conductor => csharp-examples}/Examples/GreetingsMain.cs | 0 .../Examples/Orkes/OpenAIChatGpt.cs | 0 .../Examples/Orkes/OpenAIChatUserInput.cs | 0 .../Examples/Orkes/OpenAIFunctionExample.cs | 0 .../Examples/Orkes/OpenAIHelloworld.cs | 0 {Conductor => csharp-examples}/Examples/Orkes/SyncUpdates.cs | 0 .../Examples/Orkes/TaskStatusChangeAudit.cs | 4 ++-- .../Examples/Orkes/VectorDbHelloWorld.cs | 0 .../Examples/Orkes/WaitForWebhook.cs | 0 .../Examples/Orkes/Workers/ChatWorkers.cs | 0 .../Examples/Orkes/Workers/ConversationCollector.cs | 0 .../Examples/Orkes/Workers/UserDetails.cs | 0 .../Examples/Orkes/WorkflowRerun.cs | 0 {Conductor => csharp-examples}/Examples/ShellWorker.cs | 0 {Conductor => csharp-examples}/Examples/TaskConfigure.cs | 0 {Conductor => csharp-examples}/Examples/TaskWorkers.cs | 0 .../Examples/Utils/ReRunWorkflow.json | 0 {Conductor => csharp-examples}/Examples/Utils/WorkerUtil.cs | 0 .../Examples/Workers/DynamicWorker.cs | 0 .../Examples/Workers/GreetingsWorkflow.cs | 0 csharp-examples/csharp-examples.csproj | 2 +- 27 files changed, 6 insertions(+), 5 deletions(-) rename {Conductor => csharp-examples}/Examples/Copilot/Customer.cs (100%) rename {Conductor => csharp-examples}/Examples/Copilot/OpenAICopilot.cs (100%) rename {Conductor => csharp-examples}/Examples/DynamicWorkflow.cs (100%) rename {Conductor => csharp-examples}/Examples/ExampleConstant.cs (100%) rename {Conductor => csharp-examples}/Examples/GreetingsMain.cs (100%) rename {Conductor => csharp-examples}/Examples/Orkes/OpenAIChatGpt.cs (100%) rename {Conductor => csharp-examples}/Examples/Orkes/OpenAIChatUserInput.cs (100%) rename {Conductor => csharp-examples}/Examples/Orkes/OpenAIFunctionExample.cs (100%) rename {Conductor => csharp-examples}/Examples/Orkes/OpenAIHelloworld.cs (100%) rename {Conductor => csharp-examples}/Examples/Orkes/SyncUpdates.cs (100%) rename {Conductor => csharp-examples}/Examples/Orkes/TaskStatusChangeAudit.cs (97%) rename {Conductor => csharp-examples}/Examples/Orkes/VectorDbHelloWorld.cs (100%) rename {Conductor => csharp-examples}/Examples/Orkes/WaitForWebhook.cs (100%) rename {Conductor => csharp-examples}/Examples/Orkes/Workers/ChatWorkers.cs (100%) rename {Conductor => csharp-examples}/Examples/Orkes/Workers/ConversationCollector.cs (100%) rename {Conductor => csharp-examples}/Examples/Orkes/Workers/UserDetails.cs (100%) rename {Conductor => csharp-examples}/Examples/Orkes/WorkflowRerun.cs (100%) rename {Conductor => csharp-examples}/Examples/ShellWorker.cs (100%) rename {Conductor => csharp-examples}/Examples/TaskConfigure.cs (100%) rename {Conductor => csharp-examples}/Examples/TaskWorkers.cs (100%) rename {Conductor => csharp-examples}/Examples/Utils/ReRunWorkflow.json (100%) rename {Conductor => csharp-examples}/Examples/Utils/WorkerUtil.cs (100%) rename {Conductor => csharp-examples}/Examples/Workers/DynamicWorker.cs (100%) rename {Conductor => csharp-examples}/Examples/Workers/GreetingsWorkflow.cs (100%) diff --git a/Conductor/conductor-csharp.csproj b/Conductor/conductor-csharp.csproj index 1ad67cc..38fa951 100644 --- a/Conductor/conductor-csharp.csproj +++ b/Conductor/conductor-csharp.csproj @@ -16,7 +16,7 @@ - + \ No newline at end of file diff --git a/Tests/conductor-csharp.test.csproj b/Tests/conductor-csharp.test.csproj index e9a3727..cfabaf4 100644 --- a/Tests/conductor-csharp.test.csproj +++ b/Tests/conductor-csharp.test.csproj @@ -1,6 +1,6 @@ - netcoreapp6.0 + net8.0 @@ -9,6 +9,7 @@ + diff --git a/Conductor/Examples/Copilot/Customer.cs b/csharp-examples/Examples/Copilot/Customer.cs similarity index 100% rename from Conductor/Examples/Copilot/Customer.cs rename to csharp-examples/Examples/Copilot/Customer.cs diff --git a/Conductor/Examples/Copilot/OpenAICopilot.cs b/csharp-examples/Examples/Copilot/OpenAICopilot.cs similarity index 100% rename from Conductor/Examples/Copilot/OpenAICopilot.cs rename to csharp-examples/Examples/Copilot/OpenAICopilot.cs diff --git a/Conductor/Examples/DynamicWorkflow.cs b/csharp-examples/Examples/DynamicWorkflow.cs similarity index 100% rename from Conductor/Examples/DynamicWorkflow.cs rename to csharp-examples/Examples/DynamicWorkflow.cs diff --git a/Conductor/Examples/ExampleConstant.cs b/csharp-examples/Examples/ExampleConstant.cs similarity index 100% rename from Conductor/Examples/ExampleConstant.cs rename to csharp-examples/Examples/ExampleConstant.cs diff --git a/Conductor/Examples/GreetingsMain.cs b/csharp-examples/Examples/GreetingsMain.cs similarity index 100% rename from Conductor/Examples/GreetingsMain.cs rename to csharp-examples/Examples/GreetingsMain.cs diff --git a/Conductor/Examples/Orkes/OpenAIChatGpt.cs b/csharp-examples/Examples/Orkes/OpenAIChatGpt.cs similarity index 100% rename from Conductor/Examples/Orkes/OpenAIChatGpt.cs rename to csharp-examples/Examples/Orkes/OpenAIChatGpt.cs diff --git a/Conductor/Examples/Orkes/OpenAIChatUserInput.cs b/csharp-examples/Examples/Orkes/OpenAIChatUserInput.cs similarity index 100% rename from Conductor/Examples/Orkes/OpenAIChatUserInput.cs rename to csharp-examples/Examples/Orkes/OpenAIChatUserInput.cs diff --git a/Conductor/Examples/Orkes/OpenAIFunctionExample.cs b/csharp-examples/Examples/Orkes/OpenAIFunctionExample.cs similarity index 100% rename from Conductor/Examples/Orkes/OpenAIFunctionExample.cs rename to csharp-examples/Examples/Orkes/OpenAIFunctionExample.cs diff --git a/Conductor/Examples/Orkes/OpenAIHelloworld.cs b/csharp-examples/Examples/Orkes/OpenAIHelloworld.cs similarity index 100% rename from Conductor/Examples/Orkes/OpenAIHelloworld.cs rename to csharp-examples/Examples/Orkes/OpenAIHelloworld.cs diff --git a/Conductor/Examples/Orkes/SyncUpdates.cs b/csharp-examples/Examples/Orkes/SyncUpdates.cs similarity index 100% rename from Conductor/Examples/Orkes/SyncUpdates.cs rename to csharp-examples/Examples/Orkes/SyncUpdates.cs diff --git a/Conductor/Examples/Orkes/TaskStatusChangeAudit.cs b/csharp-examples/Examples/Orkes/TaskStatusChangeAudit.cs similarity index 97% rename from Conductor/Examples/Orkes/TaskStatusChangeAudit.cs rename to csharp-examples/Examples/Orkes/TaskStatusChangeAudit.cs index 1f7156c..5f0071c 100644 --- a/Conductor/Examples/Orkes/TaskStatusChangeAudit.cs +++ b/csharp-examples/Examples/Orkes/TaskStatusChangeAudit.cs @@ -60,13 +60,13 @@ public void AuditLog(object workflowInput, string status, string name) } [WorkerTask(taskType: "simple_task_1", batchSize: 5, pollIntervalMs: 200, workerId: "workerId")] - public static string SimpleTask1(Task task) + public static string SimpleTask1(Conductor.Client.Models.Task task) { return "OK"; } [WorkerTask(taskType: "simple_task_2", batchSize: 5, pollIntervalMs: 200, workerId: "workerId")] - public static TaskResult SimpleTask2(Task task) + public static TaskResult SimpleTask2(Conductor.Client.Models.Task task) { return new TaskResult { Status = TaskResult.StatusEnum.FAILEDWITHTERMINALERROR }; } diff --git a/Conductor/Examples/Orkes/VectorDbHelloWorld.cs b/csharp-examples/Examples/Orkes/VectorDbHelloWorld.cs similarity index 100% rename from Conductor/Examples/Orkes/VectorDbHelloWorld.cs rename to csharp-examples/Examples/Orkes/VectorDbHelloWorld.cs diff --git a/Conductor/Examples/Orkes/WaitForWebhook.cs b/csharp-examples/Examples/Orkes/WaitForWebhook.cs similarity index 100% rename from Conductor/Examples/Orkes/WaitForWebhook.cs rename to csharp-examples/Examples/Orkes/WaitForWebhook.cs diff --git a/Conductor/Examples/Orkes/Workers/ChatWorkers.cs b/csharp-examples/Examples/Orkes/Workers/ChatWorkers.cs similarity index 100% rename from Conductor/Examples/Orkes/Workers/ChatWorkers.cs rename to csharp-examples/Examples/Orkes/Workers/ChatWorkers.cs diff --git a/Conductor/Examples/Orkes/Workers/ConversationCollector.cs b/csharp-examples/Examples/Orkes/Workers/ConversationCollector.cs similarity index 100% rename from Conductor/Examples/Orkes/Workers/ConversationCollector.cs rename to csharp-examples/Examples/Orkes/Workers/ConversationCollector.cs diff --git a/Conductor/Examples/Orkes/Workers/UserDetails.cs b/csharp-examples/Examples/Orkes/Workers/UserDetails.cs similarity index 100% rename from Conductor/Examples/Orkes/Workers/UserDetails.cs rename to csharp-examples/Examples/Orkes/Workers/UserDetails.cs diff --git a/Conductor/Examples/Orkes/WorkflowRerun.cs b/csharp-examples/Examples/Orkes/WorkflowRerun.cs similarity index 100% rename from Conductor/Examples/Orkes/WorkflowRerun.cs rename to csharp-examples/Examples/Orkes/WorkflowRerun.cs diff --git a/Conductor/Examples/ShellWorker.cs b/csharp-examples/Examples/ShellWorker.cs similarity index 100% rename from Conductor/Examples/ShellWorker.cs rename to csharp-examples/Examples/ShellWorker.cs diff --git a/Conductor/Examples/TaskConfigure.cs b/csharp-examples/Examples/TaskConfigure.cs similarity index 100% rename from Conductor/Examples/TaskConfigure.cs rename to csharp-examples/Examples/TaskConfigure.cs diff --git a/Conductor/Examples/TaskWorkers.cs b/csharp-examples/Examples/TaskWorkers.cs similarity index 100% rename from Conductor/Examples/TaskWorkers.cs rename to csharp-examples/Examples/TaskWorkers.cs diff --git a/Conductor/Examples/Utils/ReRunWorkflow.json b/csharp-examples/Examples/Utils/ReRunWorkflow.json similarity index 100% rename from Conductor/Examples/Utils/ReRunWorkflow.json rename to csharp-examples/Examples/Utils/ReRunWorkflow.json diff --git a/Conductor/Examples/Utils/WorkerUtil.cs b/csharp-examples/Examples/Utils/WorkerUtil.cs similarity index 100% rename from Conductor/Examples/Utils/WorkerUtil.cs rename to csharp-examples/Examples/Utils/WorkerUtil.cs diff --git a/Conductor/Examples/Workers/DynamicWorker.cs b/csharp-examples/Examples/Workers/DynamicWorker.cs similarity index 100% rename from Conductor/Examples/Workers/DynamicWorker.cs rename to csharp-examples/Examples/Workers/DynamicWorker.cs diff --git a/Conductor/Examples/Workers/GreetingsWorkflow.cs b/csharp-examples/Examples/Workers/GreetingsWorkflow.cs similarity index 100% rename from Conductor/Examples/Workers/GreetingsWorkflow.cs rename to csharp-examples/Examples/Workers/GreetingsWorkflow.cs diff --git a/csharp-examples/csharp-examples.csproj b/csharp-examples/csharp-examples.csproj index 71d7134..00b0aee 100644 --- a/csharp-examples/csharp-examples.csproj +++ b/csharp-examples/csharp-examples.csproj @@ -14,7 +14,7 @@ - + From c152d22469048169d7a643ea4ff1424284a68f59 Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Wed, 4 Dec 2024 11:49:24 -0300 Subject: [PATCH 04/12] Downgrade to net6.0 --- Tests/conductor-csharp.test.csproj | 2 +- csharp-examples/TestWorker.cs | 12 ++++++++++-- csharp-examples/csharp-examples.csproj | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Tests/conductor-csharp.test.csproj b/Tests/conductor-csharp.test.csproj index cfabaf4..f6af481 100644 --- a/Tests/conductor-csharp.test.csproj +++ b/Tests/conductor-csharp.test.csproj @@ -1,6 +1,6 @@ - net8.0 + net6.0 diff --git a/csharp-examples/TestWorker.cs b/csharp-examples/TestWorker.cs index 2fc6b4b..39aa281 100644 --- a/csharp-examples/TestWorker.cs +++ b/csharp-examples/TestWorker.cs @@ -18,11 +18,19 @@ namespace csharp.examples; -public class TestWorker(string taskType) : IWorkflowTask +public class TestWorker : IWorkflowTask { + private readonly Random rnd = new(); - public string TaskType { get; } = taskType; + private readonly string _taskType; + + public TestWorker(string taskType) + { + _taskType = taskType; + } + + public string TaskType => _taskType; public WorkflowTaskExecutorConfiguration WorkerSettings { get; } = new WorkflowTaskExecutorConfiguration() { BatchSize = 20 diff --git a/csharp-examples/csharp-examples.csproj b/csharp-examples/csharp-examples.csproj index 00b0aee..4a5dd21 100644 --- a/csharp-examples/csharp-examples.csproj +++ b/csharp-examples/csharp-examples.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net6.0 csharp_examples enable enable From 4d9d398e4b92005cd875c783a7ced7c9075921ef Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Wed, 4 Dec 2024 11:51:53 -0300 Subject: [PATCH 05/12] Renamed field --- csharp-examples/TestWorker.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/csharp-examples/TestWorker.cs b/csharp-examples/TestWorker.cs index 39aa281..a1ce28e 100644 --- a/csharp-examples/TestWorker.cs +++ b/csharp-examples/TestWorker.cs @@ -23,14 +23,14 @@ public class TestWorker : IWorkflowTask private readonly Random rnd = new(); - private readonly string _taskType; + private readonly string taskType; public TestWorker(string taskType) { - _taskType = taskType; + this.taskType = taskType; } - public string TaskType => _taskType; + public string TaskType => taskType; public WorkflowTaskExecutorConfiguration WorkerSettings { get; } = new WorkflowTaskExecutorConfiguration() { BatchSize = 20 From be11e9460e3238373deab4e8b345d311c165c3c3 Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Wed, 4 Dec 2024 12:01:36 -0300 Subject: [PATCH 06/12] Copy csharp-examples project to run tests --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 36a20bc..62d91d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,7 @@ ARG CONDUCTOR_SERVER_URL ENV KEY=${KEY} ENV SECRET=${SECRET} ENV CONDUCTOR_SERVER_URL=${CONDUCTOR_SERVER_URL} +COPY /csharp-examples /package/csharp-examples COPY /Tests /package/Tests WORKDIR /package/Tests RUN dotnet test -l "console;verbosity=normal" From 3771dc4943ee4143b2826551f85bf94c56744f5a Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Wed, 4 Dec 2024 17:57:54 -0300 Subject: [PATCH 07/12] Tests are throwing OperationCanceledException because of these 20 sec timeouts. So, I had to increase it to prevent test being aborted. "The active test run was aborted. Reason: Test host process crashed : Unhandled exception. System.OperationCanceledException: The operation was canceled." --- Tests/Worker/WorkerTests.cs | 2 +- Tests/conductor-csharp.test.csproj | 1 - csharp-examples/Examples/Utils/WorkerUtil.cs | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Tests/Worker/WorkerTests.cs b/Tests/Worker/WorkerTests.cs index 64f4159..463475a 100644 --- a/Tests/Worker/WorkerTests.cs +++ b/Tests/Worker/WorkerTests.cs @@ -47,7 +47,7 @@ public async System.Threading.Tasks.Task TestWorkflowAsyncExecution() var workflow = GetConductorWorkflow(); ApiExtensions.GetWorkflowExecutor().RegisterWorkflow(workflow, true); var workflowIdList = await StartWorkflows(workflow, quantity: 15); - await ExecuteWorkflowTasks(workflowCompletionTimeout: TimeSpan.FromSeconds(20)); + await ExecuteWorkflowTasks(workflowCompletionTimeout: TimeSpan.FromSeconds(40)); await ValidateWorkflowCompletion(workflowIdList.ToArray()); } diff --git a/Tests/conductor-csharp.test.csproj b/Tests/conductor-csharp.test.csproj index f6af481..aabf637 100644 --- a/Tests/conductor-csharp.test.csproj +++ b/Tests/conductor-csharp.test.csproj @@ -8,7 +8,6 @@ - diff --git a/csharp-examples/Examples/Utils/WorkerUtil.cs b/csharp-examples/Examples/Utils/WorkerUtil.cs index 00bfe50..038e5b9 100644 --- a/csharp-examples/Examples/Utils/WorkerUtil.cs +++ b/csharp-examples/Examples/Utils/WorkerUtil.cs @@ -32,7 +32,7 @@ public static async Task StartBackGroundTask(ManualResetEvent waitHandle, { var host = WorkflowTaskHost.CreateWorkerHost(Microsoft.Extensions.Logging.LogLevel.Information); await host.StartAsync(); - Thread.Sleep(20000); + Thread.Sleep(60000); waitHandle.Set(); await host.StopAsync(); return true; From bab40a6fc888e2f981d8b3335a57270def50680d Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Wed, 4 Dec 2024 18:25:05 -0300 Subject: [PATCH 08/12] Adjust polling and batch size of test-sdk-csharp-task workers --- Tests/Worker/Workers.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/Worker/Workers.cs b/Tests/Worker/Workers.cs index 349d1ee..8461737 100644 --- a/Tests/Worker/Workers.cs +++ b/Tests/Worker/Workers.cs @@ -30,18 +30,18 @@ static FunctionalWorkers() _random = new Random(); } - // Polls for 5 task every 200ms - [WorkerTask("test-sdk-csharp-task", 5, "taskDomain", 200, "workerId")] + // Polls for 5 task every 100ms + [WorkerTask("test-sdk-csharp-task", 5, "taskDomain", 100, "simpleWorker")] public static TaskResult SimpleWorker(Conductor.Client.Models.Task task) { return task.Completed(); } - // Polls for 12 tasks every 420ms - [WorkerTask("test-sdk-csharp-task", 12, "taskDomain", 420, "workerId")] + // Polls for 5 tasks every 420ms + [WorkerTask("test-sdk-csharp-task", 5, "taskDomain", 420, "lazyWorker")] public TaskResult LazyWorker(Conductor.Client.Models.Task task) { - var timeSpan = System.TimeSpan.FromMilliseconds(_random.Next(128, 2048)); + var timeSpan = System.TimeSpan.FromMilliseconds(_random.Next(100, 900)); System.Threading.Tasks.Task.Delay(timeSpan).GetAwaiter().GetResult(); return task.Completed(); } From c34e8c2b8da185ff80f748ded27ece47b769d9c3 Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Wed, 4 Dec 2024 18:25:30 -0300 Subject: [PATCH 09/12] Fix environmentResourceApi.GetAll() --- Conductor/Api/EnvironmentResourceApi.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Conductor/Api/EnvironmentResourceApi.cs b/Conductor/Api/EnvironmentResourceApi.cs index 60b029a..732a4ea 100644 --- a/Conductor/Api/EnvironmentResourceApi.cs +++ b/Conductor/Api/EnvironmentResourceApi.cs @@ -597,9 +597,13 @@ public ApiResponse> GetAllWithHttpInfo() if (exception != null) throw exception; } + var list = (List>)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(List>)); + var dictionary = list + .Where(item => item.ContainsKey("name") && item.ContainsKey("value")) + .ToDictionary(item => item["name"], item => item["value"]); return new ApiResponse>(localVarStatusCode, - localVarResponse.Headers.ToDictionary(x => x.Name, x => string.Join(",", x.Value)), - (Dictionary)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(Dictionary))); + localVarResponse.Headers.ToDictionary(x => x.Name, x => string.Join(",", x.Value)), + dictionary); } /// From 77972930995226e4373190e7ab1d3b3694de5fa7 Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Wed, 4 Dec 2024 18:47:31 -0300 Subject: [PATCH 10/12] Adjust GitHub Workflow to avoid running jobs twice on PR --- .github/workflows/pull_request.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 9ce8a6e..bb0eed7 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -1,6 +1,13 @@ name: CI Build -on: [push, pull_request,workflow_dispatch] +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: jobs: lint: From 27201d375025a824bbaf9de4b0890ef7f68d71c0 Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Wed, 4 Dec 2024 20:35:48 -0300 Subject: [PATCH 11/12] - Allow a custom configuration in ApiExtensions - Lazily initialize from Environment variables if no custom config - Improve unset env variable error message --- Conductor/Client/Extensions/ApiExtensions.cs | 28 +++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Conductor/Client/Extensions/ApiExtensions.cs b/Conductor/Client/Extensions/ApiExtensions.cs index 7a2846f..c0878a5 100644 --- a/Conductor/Client/Extensions/ApiExtensions.cs +++ b/Conductor/Client/Extensions/ApiExtensions.cs @@ -14,7 +14,6 @@ using Conductor.Executor; using Conductor.Client.Authentication; using System; -using System.Diagnostics; namespace Conductor.Client.Extensions { @@ -25,20 +24,25 @@ public class ApiExtensions private const string ENV_SECRET = "SECRET"; private const int REST_CLIENT_REQUEST_TIME_OUT = 30 * 1000; - public static Configuration Configuration { get; set; } - - static ApiExtensions() - { - Configuration = new Configuration(REST_CLIENT_REQUEST_TIME_OUT) + private static readonly Lazy _lazyConfiguration = + new Lazy(() => new Configuration(REST_CLIENT_REQUEST_TIME_OUT) { BasePath = GetEnvironmentVariable(ENV_ROOT_URI), AuthenticationSettings = new OrkesAuthenticationSettings( - GetEnvironmentVariable(ENV_KEY_ID), - GetEnvironmentVariable(ENV_SECRET) - ) - }; + GetEnvironmentVariable(ENV_KEY_ID), + GetEnvironmentVariable(ENV_SECRET) + ) + }); + + private static Configuration _customConfiguration; + + public static Configuration Configuration + { + get => _customConfiguration ?? _lazyConfiguration.Value; + set => _customConfiguration = value; } + public static WorkflowExecutor GetWorkflowExecutor() { return new WorkflowExecutor( @@ -66,9 +70,7 @@ public static string GetWorkflowExecutionURL(string workflowId) private static string GetEnvironmentVariable(string variable) { - string value = Environment.GetEnvironmentVariable(variable); - Debug.Assert(value != null); - return value; + return Environment.GetEnvironmentVariable(variable) ?? throw new InvalidOperationException($"Environment variable '{variable}' is not set."); } } } From 87517936dd40d7581bcfb7645a9732749abf78b0 Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Wed, 4 Dec 2024 23:14:11 -0300 Subject: [PATCH 12/12] Exclude example workers from tests --- Dockerfile | 2 +- Tests/Worker/WorkerTests.cs | 2 +- csharp-examples/{Examples => }/Utils/ReRunWorkflow.json | 0 csharp-examples/{Examples => }/Utils/WorkerUtil.cs | 5 +---- csharp-examples/csharp-examples.csproj | 7 ++++++- 5 files changed, 9 insertions(+), 7 deletions(-) rename csharp-examples/{Examples => }/Utils/ReRunWorkflow.json (100%) rename csharp-examples/{Examples => }/Utils/WorkerUtil.cs (93%) diff --git a/Dockerfile b/Dockerfile index 62d91d3..042cb42 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,7 +20,7 @@ ENV CONDUCTOR_SERVER_URL=${CONDUCTOR_SERVER_URL} COPY /csharp-examples /package/csharp-examples COPY /Tests /package/Tests WORKDIR /package/Tests -RUN dotnet test -l "console;verbosity=normal" +RUN dotnet test -p:DefineConstants=EXCLUDE_EXAMPLE_WORKERS -l "console;verbosity=normal" FROM build as pack_release ARG SDK_VERSION diff --git a/Tests/Worker/WorkerTests.cs b/Tests/Worker/WorkerTests.cs index 463475a..3ad706b 100644 --- a/Tests/Worker/WorkerTests.cs +++ b/Tests/Worker/WorkerTests.cs @@ -47,7 +47,7 @@ public async System.Threading.Tasks.Task TestWorkflowAsyncExecution() var workflow = GetConductorWorkflow(); ApiExtensions.GetWorkflowExecutor().RegisterWorkflow(workflow, true); var workflowIdList = await StartWorkflows(workflow, quantity: 15); - await ExecuteWorkflowTasks(workflowCompletionTimeout: TimeSpan.FromSeconds(40)); + await ExecuteWorkflowTasks(workflowCompletionTimeout: TimeSpan.FromSeconds(30)); await ValidateWorkflowCompletion(workflowIdList.ToArray()); } diff --git a/csharp-examples/Examples/Utils/ReRunWorkflow.json b/csharp-examples/Utils/ReRunWorkflow.json similarity index 100% rename from csharp-examples/Examples/Utils/ReRunWorkflow.json rename to csharp-examples/Utils/ReRunWorkflow.json diff --git a/csharp-examples/Examples/Utils/WorkerUtil.cs b/csharp-examples/Utils/WorkerUtil.cs similarity index 93% rename from csharp-examples/Examples/Utils/WorkerUtil.cs rename to csharp-examples/Utils/WorkerUtil.cs index 038e5b9..1348f51 100644 --- a/csharp-examples/Examples/Utils/WorkerUtil.cs +++ b/csharp-examples/Utils/WorkerUtil.cs @@ -12,9 +12,6 @@ */ using Conductor.Client.Extensions; using Conductor.Client.Interfaces; -using System; -using System.Threading; -using System.Threading.Tasks; namespace Conductor.Examples.Utils { @@ -32,7 +29,7 @@ public static async Task StartBackGroundTask(ManualResetEvent waitHandle, { var host = WorkflowTaskHost.CreateWorkerHost(Microsoft.Extensions.Logging.LogLevel.Information); await host.StartAsync(); - Thread.Sleep(60000); + Thread.Sleep(40000); waitHandle.Set(); await host.StopAsync(); return true; diff --git a/csharp-examples/csharp-examples.csproj b/csharp-examples/csharp-examples.csproj index 4a5dd21..0b28ab8 100644 --- a/csharp-examples/csharp-examples.csproj +++ b/csharp-examples/csharp-examples.csproj @@ -10,11 +10,16 @@ - + + + + +