-
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.
Added Examples to test the Workflow Execution
- Loading branch information
1 parent
99848f2
commit c649dff
Showing
19 changed files
with
638 additions
and
172 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
/* | ||
* Copyright 2024 Conductor Authors. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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. | ||
*/ | ||
* Copyright 2024 Conductor Authors. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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. | ||
*/ | ||
using conductor.Examples; | ||
using Conductor.Api; | ||
using Conductor.Client; | ||
using Conductor.Client.Extensions; | ||
using Conductor.Client.Models; | ||
using Conductor.Client.Worker; | ||
using Conductor.Definition; | ||
using Conductor.Definition.TaskType; | ||
using Conductor.Examples.Workers; | ||
using Conductor.Executor; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
|
||
namespace Conductor.Examples | ||
{ | ||
[WorkerTask] | ||
public class DynamicWorkflow | ||
{ | ||
private readonly WorkflowResourceApi _workflowClient; | ||
|
@@ -47,13 +48,13 @@ public DynamicWorkflow() | |
//_metaDataClient = _orkesApiClient.GetClient<MetadataResourceApi>(); | ||
} | ||
|
||
[WorkerTask(taskType: "GetEmail", 5, "taskDomain", 520, "workerId")] | ||
[WorkerTask(taskType: ExampleConstants.GetEmail, batchSize: 5, pollIntervalMs: 520, workerId: "workerId")] | ||
public string GetUserEmail(string userId) | ||
{ | ||
return $"{userId}@example.com"; | ||
} | ||
|
||
[WorkerTask(taskType: "SendEmail", 5, "taskDomain", 520, "workerId")] | ||
[WorkerTask(taskType: ExampleConstants.SendEmail, batchSize: 5, pollIntervalMs: 520, workerId: "workerId")] | ||
public string SendEmail(string email, string subject, string body) | ||
{ | ||
return $"sending email to {email} with subject {subject} and body {body}"; | ||
|
@@ -68,39 +69,44 @@ public void DynamicWorkFlowMain() | |
|
||
workflow.WithInputParameter("userId"); | ||
|
||
//Once the annotator is ready we have to remove this piece of code as the task creation will be taken care inside the wrapper method | ||
var getEmailTask = new SimpleTask("GetEmail", "GetEmail").WithInput("InputVaraible", workflow.Input("userId")); | ||
getEmailTask.Description = "Test Get email"; | ||
var getEmailTask = new SimpleTask(ExampleConstants.GetEmail, ExampleConstants.GetEmail).WithInput("userId", workflow.Input("userId")); | ||
getEmailTask.Description = ExampleConstants.GetEmailDescription; | ||
workflow.WithTask(getEmailTask); | ||
|
||
var SendEmailTask = new SimpleTask("SendEmail", "Send_Email_refTask").WithInput("InputVaraible", workflow.Input("userId")); | ||
SendEmailTask.Description = "Test Get email"; | ||
var SendEmailTask = new SimpleTask(ExampleConstants.SendEmail, ExampleConstants.SendEmail).WithInput("email", workflow.Input("email")).WithInput("subject", workflow.Input("subject")).WithInput("body", workflow.Input("body")); | ||
SendEmailTask.Description = ExampleConstants.SendEmailDescription; | ||
workflow.WithTask(SendEmailTask); | ||
|
||
TaskDef taskDef = new TaskDef() { Description = "test", Name = "dynamic_workflow-task" }; | ||
List<TaskDef> taskDefs = new List<TaskDef>() | ||
{ | ||
new TaskDef{Description = ExampleConstants.GetEmailDescription, Name = ExampleConstants.GetEmail }, | ||
new TaskDef{Description = ExampleConstants.SendEmailDescription,Name = ExampleConstants.SendEmail} | ||
}; | ||
|
||
_metaDataClient.RegisterTaskDef(new List<TaskDef>() { taskDef }); | ||
_workflowExecutor.RegisterWorkflow(workflow, true); | ||
_metaDataClient.RegisterTaskDef(taskDefs); | ||
_metaDataClient.UpdateWorkflowDefinitions(new List<WorkflowDef>(1) { workflow }); | ||
|
||
var testInput = new Dictionary<string, object> | ||
{ | ||
{ "userId", "Test" } | ||
{ "userId", "Test" }, | ||
{ "email", "[email protected]" }, | ||
{ "subject", "SubjectTest" }, | ||
{ "body" , "BodyDescription" } | ||
}; | ||
|
||
StartWorkflowRequest startWorkflow = new StartWorkflowRequest() | ||
StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest() | ||
{ | ||
Name = workflow.Name, | ||
Input = testInput, | ||
Version = workflow.Version, | ||
WorkflowDef = workflow, | ||
CreatedBy = Constants.OWNER_EMAIL | ||
CreatedBy = Constants.OWNER_EMAIL, | ||
}; | ||
|
||
var workflowTask = _workflowExecutor.StartWorkflow(startWorkflow); | ||
_workflowClient.StartWorkflow(startWorkflowRequest); | ||
var waitHandle = new ManualResetEvent(false); | ||
|
||
//For testing purpose the worker is created manually for now. Once the annotation logic is in place we can getrid of this | ||
var backgroundTask = System.Threading.Tasks.Task.Run(async () => await Utils.WorkerUtil.StartBackGroundTask(waitHandle, new DynamicWorker("GetEmail"))); | ||
var backgroundTask = System.Threading.Tasks.Task.Run(async () => await Utils.WorkerUtil.StartBackGroundTask(waitHandle)); | ||
waitHandle.WaitOne(); | ||
} | ||
} | ||
|
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
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
Oops, something went wrong.