conductor-csharp
0.0.1
See the version list below for details.
dotnet add package conductor-csharp --version 0.0.1
NuGet\Install-Package conductor-csharp -Version 0.0.1
<PackageReference Include="conductor-csharp" Version="0.0.1" />
paket add conductor-csharp --version 0.0.1
#r "nuget: conductor-csharp, 0.0.1"
// Install conductor-csharp as a Cake Addin #addin nuget:?package=conductor-csharp&version=0.0.1 // Install conductor-csharp as a Cake Tool #tool nuget:?package=conductor-csharp&version=0.0.1
conductor-csharp
Netflix Conductor Client SDK
To find out more about Conductor visit: https://github.com/Netflix/conductor
conductor-csharp
repository provides the client SDKs to build Task Workers in C#
Quick Start
Write workers
internal class MyWorkflowTask : IWorkflowTask
{
public MyWorkflowTask(){}
public string TaskType => "test_ctask";
public int? Priority => null;
public async Task<TaskResult> Execute(Conductor.Client.Models.Task task, CancellationToken token)
{
Dictionary<string, object> newOutput = new Dictionary<string, object>();
newOutput.Add("output", "1");
return task.Completed(task.OutputData.MergeValues(newOutput));
}
}
internal class MyWorkflowTask2 : IWorkflowTask
{
public MyWorkflowTask2(){}
public string TaskType => "test_ctask2";
public int? Priority => null;
public async Task<TaskResult> Execute(Conductor.Client.Models.Task task, CancellationToken token)
{
Dictionary<string, object> newOutput = new Dictionary<string, object>();
//Reuse the existing code written in C#
newOutput.Add("output", "success");
return task.Completed(task.OutputData.MergeValues(newOutput));
}
}
Run workers
Create main method that does the following:
- Adds configurations such as metrics, authentication, thread count, Conductor server URL
- Add your workers
- Start the workers to poll for work
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Conductor.Client.Models;
using Conductor.Client.Extensions;
using Conductor.Client.Interfaces;
using Task = System.Threading.Tasks.Task;
namespace SimpleConductorWorker
{
class Program
{
static async Task Main(string[] args)
{
await new HostBuilder()
.ConfigureServices((ctx, services) =>
{
# Conductor server url
services.AddConductorWorker((config) =>
{
config.ServerUrl = new Uri("http://localhost:8080/api/");
});
# Optionally, if you are using Conductor server that requires authentication, setup key_id and secret
config.AuthenticationClient = new Conductor.Client.AuthenticationClient()
{
keyId = "key",
keySecret = "secret"
};
services.AddConductorWorkflowTask<MyWorkflowTask>();
services.AddHostedService<WorkflowsWorkerService>();
})
.ConfigureLogging(logging =>
{
logging.SetMinimumLevel(LogLevel.Debug);
logging.AddConsole();
})
.RunConsoleAsync();
}
}
internal class WorkflowsWorkerService : BackgroundService
{
private readonly IWorkflowTaskCoordinator workflowTaskCoordinator;
private readonly IEnumerable<IWorkflowTask> workflowTasks;
public WorkflowsWorkerService(
IWorkflowTaskCoordinator workflowTaskCoordinator,
IEnumerable<IWorkflowTask> workflowTasks
)
{
this.workflowTaskCoordinator = workflowTaskCoordinator;
this.workflowTasks = workflowTasks;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
foreach (var worker in workflowTasks)
{
workflowTaskCoordinator.RegisterWorker(worker);
}
# start all the workers so that it can poll for the tasks
await workflowTaskCoordinator.Start();
}
}
}
Save above code with workers code in Program.cs and run it using consoleApplication. Alternatively it can also be hosted as windows service.
Running Conductor server locally in 2-minute
More details on how to run Conductor see https://netflix.github.io/conductor/server/
Use the script below to download and start the server locally. The server runs in memory and no data saved upon exit.
export CONDUCTOR_VER=3.5.2
export REPO_URL=https://repo1.maven.org/maven2/com/netflix/conductor/conductor-server
curl $REPO_URL/$CONDUCTOR_VER/conductor-server-$CONDUCTOR_VER-boot.jar \
--output conductor-server-$CONDUCTOR_VER-boot.jar; java -jar conductor-server-$CONDUCTOR_VER-boot.jar
Execute workers
Run above program as console app or windows service
Create your first workflow
Now, let's create a new workflow and see your task worker code in execution!
Create a new Task Metadata for the worker you just created
curl -X 'POST' \
'http://localhost:8080/api/metadata/taskdefs' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '[{
"name": "test_ctask",
"description": "C# task example",
"retryCount": 3,
"retryLogic": "FIXED",
"retryDelaySeconds": 10,
"timeoutSeconds": 300,
"timeoutPolicy": "TIME_OUT_WF",
"responseTimeoutSeconds": 180,
"ownerEmail": "example@example.com"
}]'
Create a workflow that uses the task
curl -X 'POST' \
'http://localhost:8080/api/metadata/workflow' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"name": "workflow_with_csharp_task_example",
"description": "Workflow with C# Task example",
"version": 1,
"tasks": [
{
"name": "test_ctask",
"taskReferenceName": "test_ctask",
"inputParameters": {},
"type": "SIMPLE"
}
],
"inputParameters": [],
"outputParameters": {
"workerOutput": "${test_ctask.output}"
},
"schemaVersion": 2,
"restartable": true,
"ownerEmail": "example@example.com",
"timeoutPolicy": "ALERT_ONLY",
"timeoutSeconds": 0
}'
Start a new workflow execution
curl -X 'POST' \
'http://localhost:8080/api/workflow/workflow_with_csharp_task_example?priority=0' \
-H 'accept: text/plain' \
-H 'Content-Type: application/json' \
-d '{}'
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Http (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 6.0.0)
- Newtonsoft.Json (>= 13.0.1)
- System.ComponentModel.Annotations (>= 5.0.0)
- System.Net.Http.Json (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.1.0 | 258 | 12/9/2024 |
1.0.15 | 15,885 | 6/6/2024 |
1.0.14 | 62,789 | 3/19/2024 |
1.0.13 | 4,750 | 1/4/2024 |
1.0.12 | 31,707 | 8/29/2023 |
1.0.11 | 19,260 | 5/11/2023 |
1.0.10 | 197 | 5/11/2023 |
1.0.9 | 202 | 5/9/2023 |
1.0.8 | 206 | 5/8/2023 |
1.0.7 | 1,067 | 3/23/2023 |
1.0.6 | 253 | 3/22/2023 |
1.0.5 | 248 | 3/22/2023 |
1.0.4 | 301 | 3/16/2023 |
1.0.3 | 279 | 3/15/2023 |
1.0.2 | 277 | 3/15/2023 |
1.0.1 | 260 | 3/12/2023 |
1.0.0 | 313 | 3/6/2023 |
0.1.10 | 132,392 | 2/12/2023 |
0.1.9 | 326 | 2/11/2023 |
0.1.8 | 1,024 | 1/25/2023 |
0.1.7 | 19,641 | 1/3/2023 |
0.1.6 | 20,023 | 12/19/2022 |
0.1.5 | 365 | 12/15/2022 |
0.1.3 | 364 | 12/15/2022 |
0.1.1 | 371 | 12/15/2022 |
0.1.0 | 411 | 12/3/2022 |
0.0.9 | 397 | 12/3/2022 |
0.0.8 | 397 | 12/3/2022 |
0.0.7 | 396 | 12/3/2022 |
0.0.6 | 2,736 | 9/15/2022 |
0.0.5 | 963 | 4/15/2022 |
0.0.4 | 472 | 4/14/2022 |
0.0.3 | 491 | 4/13/2022 |
0.0.2 | 472 | 4/7/2022 |
0.0.1 | 501 | 4/6/2022 |