-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to address UpdateVariableFunctionality and Inprogress throwin…
…g error issue (#100) * Changes to address the below 1. update variables functionality, 2. Inprogress throws exception when default param value after callbackAfterSeconds * Revert "Changes to address the below" This reverts commit 67d56b4. * Changes to address the below 1. update variables functionality, 2. Inprogress throws exception when default param value after callbackAfterSeconds * Resolved lint whitespace errors * Fixing the space issues --------- Co-authored-by: Jithesh.Poojary <Jithesh.Poojary@TL300>
- Loading branch information
1 parent
ae86f42
commit 399ed7c
Showing
6 changed files
with
257 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,97 @@ | ||
using conductor.csharp.Client.Extensions; | ||
using Conductor.Api; | ||
using Conductor.Client.Extensions; | ||
using Conductor.Client.Models; | ||
using Conductor.Definition; | ||
using Conductor.Definition.TaskType; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using Tests.Worker; | ||
using Xunit; | ||
|
||
namespace conductor_csharp.test.Api | ||
{ | ||
public class WorkflowResourceApiTest | ||
{ | ||
private const string WORKFLOW_NAME = "TestToCreateVariables"; | ||
private const string TASK_NAME = "TestToCreateVariables_Task"; | ||
private const string WORKFLOW_VARIABLE_1 = "TestVariable1"; | ||
private const string WORKFLOW_VARIABLE_2 = "TestVariable2"; | ||
private const string WORKFLOW_DESC = "Test Workflow With Variables"; | ||
private const int WORKFLOW_VERSION = 1; | ||
|
||
private readonly WorkflowResourceApi _workflowClient; | ||
private readonly ILogger _logger; | ||
|
||
public WorkflowResourceApiTest() | ||
{ | ||
_workflowClient = ApiExtensions.GetClient<WorkflowResourceApi>(); | ||
_logger = ApplicationLogging.CreateLogger<WorkerTests>(); | ||
} | ||
|
||
[Fact] | ||
public async void UpdateWorkflowVariables() | ||
{ | ||
// Prepare workflow | ||
var _workflow = GetConductorWorkflow(); | ||
ApiExtensions.GetWorkflowExecutor().RegisterWorkflow(_workflow, true); | ||
var workflowId = ApiExtensions.GetWorkflowExecutor().StartWorkflow(_workflow); | ||
await ExecuteWorkflowTasks(workflowCompletionTimeout: TimeSpan.FromSeconds(20)); | ||
await ValidateWorkflowCompletion(workflowId); | ||
|
||
// Create variables collection with values to be updated | ||
var updateDict = new Dictionary<string, object> { | ||
{WORKFLOW_VARIABLE_1,"Value1" }, | ||
{WORKFLOW_VARIABLE_2,"Value2" }, | ||
}; | ||
var updateVariableData = new Workflow() { WorkflowId = workflowId, Variables = updateDict }; | ||
// Update the work flow variables | ||
_workflowClient.UpdateWorkflowVariables(updateVariableData); | ||
// Fetch latest workflow data to validate the change in variables | ||
var _updatedWorkFlow = _workflowClient.GetWorkflowStatusSummary(workflowId, includeVariables: true); | ||
// Verify workflow variables data is equal with input passed | ||
Assert.Equal(_updatedWorkFlow.Variables, updateDict); | ||
} | ||
|
||
private async System.Threading.Tasks.Task ExecuteWorkflowTasks(TimeSpan workflowCompletionTimeout) | ||
{ | ||
var host = WorkflowTaskHost.CreateWorkerHost(LogLevel.Information, new ClassWorker()); | ||
await host.StartAsync(); | ||
Thread.Sleep(workflowCompletionTimeout); | ||
await host.StopAsync(); | ||
} | ||
|
||
private ConductorWorkflow GetConductorWorkflow() | ||
{ | ||
return new ConductorWorkflow() | ||
.WithName(WORKFLOW_NAME) | ||
.WithVersion(WORKFLOW_VERSION) | ||
.WithDescription(WORKFLOW_DESC) | ||
.WithTask(new SimpleTask(TASK_NAME, TASK_NAME)) | ||
.WithVariable(WORKFLOW_VARIABLE_1, $"{WORKFLOW_VARIABLE_1}_Value") | ||
.WithVariable(WORKFLOW_VARIABLE_2, $"{WORKFLOW_VARIABLE_2}_Value"); | ||
} | ||
|
||
private async System.Threading.Tasks.Task ValidateWorkflowCompletion(params string[] workflowIdList) | ||
{ | ||
var workflowStatusList = await WorkflowExtensions.GetWorkflowStatusList( | ||
_workflowClient, | ||
maxAllowedInParallel: 10, | ||
workflowIdList | ||
); | ||
var incompleteWorkflowCounter = 0; | ||
workflowStatusList.ToList().ForEach(wf => | ||
{ | ||
if (wf.Status.Value != WorkflowStatus.StatusEnum.COMPLETED) | ||
{ | ||
incompleteWorkflowCounter += 1; | ||
_logger.LogInformation($"Workflow not completed, workflowId: {wf.WorkflowId}"); | ||
} | ||
}); | ||
Assert.Equal(0, incompleteWorkflowCounter); | ||
} | ||
} | ||
} |
This file contains 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 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,77 @@ | ||
using Conductor.Client; | ||
using Conductor.Definition.TaskType; | ||
using Conductor.Definition; | ||
using Conductor.Executor; | ||
using Conductor.Api; | ||
using Conductor.Client.Authentication; | ||
|
||
namespace csharp_examples | ||
{ | ||
public class WorkFlowExamples | ||
{ | ||
|
||
private const string KEY_ID = "<REPLACE_WITH_KEY_ID>"; | ||
private const string KEY_SECRET = "<REPLACE_WITH_KEY_SECRET>"; | ||
private const string OWNER_EMAIL = "<REPLACE_WITH_OWNER_EMAIL>"; | ||
|
||
private const string WORKFLOW_ID = "<REPLACE_WITH_WORKFLOW_ID>"; | ||
private const string WORKFLOW_NAME = "<REPLACE_WITH_WORKFLOW_NAME>"; | ||
private const string WORKFLOW_DESCRIPTION = "<REPLACE_WITH_WORKFLOW_DESCRIPTION>"; | ||
private const string TASK_NAME = "<REPLACE_WITH_TASK_NAME >"; | ||
private const string TASK_REFERENCE = "<REPLACE_WITH_TASK_REFERENCE_NAME>"; | ||
|
||
private const string VARIABLE_OLD_VALUE = "SOME_OLD_VALUE"; | ||
private const string VARIABLE_NAME_1 = "<REPLACE_WITH_VARIABLE_NAME_1>"; | ||
private const string VARIABLE_NEW_VALUE_1 = "<REPLACE_WITH_OWNER_VALUE_1>"; | ||
private const string VARIABLE_NAME_2 = "<REPLACE_WITH_VARIABLE_NAME_2>"; | ||
private const string VARIABLE_NEW_VALUE_2 = "<REPLACE_WITH_OWNER_VALUE_2>"; | ||
|
||
|
||
public void RegisterWorkFlow() | ||
{ | ||
Configuration configuration = new Configuration() | ||
{ | ||
AuthenticationSettings = new OrkesAuthenticationSettings(KEY_ID, KEY_SECRET) | ||
}; | ||
|
||
WorkflowExecutor executor = new WorkflowExecutor(configuration); | ||
executor.RegisterWorkflow(GetConductorWorkflow(), true); | ||
} | ||
|
||
private ConductorWorkflow GetConductorWorkflow() | ||
{ | ||
var conductorWorkFlow = new ConductorWorkflow() | ||
.WithName(WORKFLOW_NAME).WithDescription(WORKFLOW_DESCRIPTION) | ||
.WithTask(new SimpleTask(TASK_NAME, TASK_REFERENCE)) | ||
.WithOwner(OWNER_EMAIL); | ||
|
||
var workflowVariableTobeAdded = new Dictionary<string, object> | ||
{ | ||
{ VARIABLE_NAME_1, VARIABLE_OLD_VALUE}, | ||
{ VARIABLE_NAME_2, VARIABLE_OLD_VALUE } | ||
}; | ||
|
||
conductorWorkFlow.Variables = workflowVariableTobeAdded; | ||
return conductorWorkFlow; | ||
} | ||
|
||
public void UpdateWorkflowVariablesWithWorkFlowId() | ||
{ | ||
var orkesApiClient = new OrkesApiClient(new Configuration(), | ||
new OrkesAuthenticationSettings(KEY_ID, KEY_SECRET)); | ||
var workflowClient = orkesApiClient.GetClient<WorkflowResourceApi>(); | ||
var workFlowVariables = new Dictionary<string, object> | ||
{ | ||
{ VARIABLE_NAME_1, VARIABLE_NEW_VALUE_1 }, | ||
{ VARIABLE_NAME_2, VARIABLE_NEW_VALUE_2 } | ||
}; | ||
|
||
workflowClient.UpdateWorkflowVariables(new Conductor.Client.Models.Workflow() | ||
{ | ||
WorkflowId = WORKFLOW_ID, | ||
Variables = workFlowVariables | ||
}); | ||
} | ||
|
||
} | ||
} |