Skip to content

Commit af6097c

Browse files
authored
Merge pull request #3 from conductor-oss/feature/csharp-worker
C# worker template
2 parents 6730d40 + fbc55fe commit af6097c

6 files changed

Lines changed: 145 additions & 0 deletions

File tree

csharp/worker/core/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Conductor C# Worker
2+
3+
Follow the instructions below to set up and run a C# worker, orchestrated by Conductor.
4+
5+
### Run the worker
6+
7+
```shell
8+
dotnet run
9+
```
10+
11+
### Conductor documentation
12+
13+
* [Core Concepts](https://orkes.io/content/core-concepts)
14+
* [Using Workers](https://orkes.io/content/developer-guides/using-workers)
15+
16+
17+
### Additional resources
18+
* [Orkes Conductor - Developer Edition](https://developer.orkescloud.com/)
19+
* [Join the community in Slack](https://orkes-conductor.slack.com) and [Discourse](https://community.orkes.io)
20+
* [Contribute to the Conductor OSS project](https://github.com/conductor-oss/conductor)

csharp/worker/core/Worker.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using Conductor.Client.Authentication;
2+
using Conductor.Client.Worker;
3+
using Conductor.Client.Models;
4+
using Conductor.Client.Extensions;
5+
using Conductor.Client;
6+
using Microsoft.Extensions.Hosting;
7+
using Microsoft.Extensions.Logging;
8+
9+
namespace Orkes.Workers
10+
{
11+
[WorkerTask]
12+
public class MyWorker
13+
{
14+
[WorkerTask(taskType: "{{taskname}}", batchSize: 5, pollIntervalMs: 500, workerId: "csharp-worker")]
15+
public static TaskResult MyTask(Conductor.Client.Models.Task task)
16+
{
17+
var inputData = task.InputData;
18+
var result = task.ToTaskResult();
19+
result.OutputData = new Dictionary<string, object>
20+
{
21+
["message"] = "Hello " + inputData.GetValueOrDefault("name", null)
22+
};
23+
return result;
24+
}
25+
26+
public static void Main(string[] args)
27+
{
28+
var conf = new Configuration
29+
{
30+
BasePath = "{{server_url}}",
31+
AuthenticationSettings = new OrkesAuthenticationSettings("{{auth_key}}", "{{auth_secret}}")
32+
};
33+
34+
var host = WorkflowTaskHost.CreateWorkerHost(conf, LogLevel.Debug);
35+
host.Start();
36+
37+
Console.WriteLine("Press Ctrl+C to exit.");
38+
var evt = new ManualResetEvent(false);
39+
Console.CancelKeyPress += (sender, e) =>
40+
{
41+
e.Cancel = true;
42+
Console.WriteLine("Ctrl+C pressed. Shutting down...");
43+
evt.Set();
44+
};
45+
46+
evt.WaitOne();
47+
host.StopAsync();
48+
}
49+
}
50+
}

csharp/worker/core/bp.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"files": [
3+
{
4+
"name": "Worker.cs",
5+
"fields": [
6+
{
7+
"name": "taskname",
8+
"prompt": "Enter a task name:"
9+
}
10+
]
11+
},
12+
{
13+
"name": "worker.csproj"
14+
},
15+
{
16+
"name": "worker.sln"
17+
},
18+
{
19+
"name": "README.md"
20+
}
21+
]
22+
}

csharp/worker/core/worker.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="conductor-csharp" Version="1.1.1" />
12+
</ItemGroup>
13+
14+
</Project>

csharp/worker/core/worker.sln

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.5.002.0
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "worker", "worker.csproj", "{471891A0-13E5-4A18-9EC7-770FD81806D5}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{471891A0-13E5-4A18-9EC7-770FD81806D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{471891A0-13E5-4A18-9EC7-770FD81806D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{471891A0-13E5-4A18-9EC7-770FD81806D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{471891A0-13E5-4A18-9EC7-770FD81806D5}.Release|Any CPU.Build.0 = Release|Any CPU
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
GlobalSection(ExtensibilityGlobals) = postSolution
22+
SolutionGuid = {DC1F001E-EEE2-4C54-9A2B-1A5B86C8F33C}
23+
EndGlobalSection
24+
EndGlobal

manifest.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
{
22
"languages": [
3+
{
4+
"name": "C#",
5+
"frameworks": [
6+
{
7+
"name": "core",
8+
"templates": [
9+
{
10+
"name": "basic-worker",
11+
"description": "Basic C# worker with Conductor SDK",
12+
"path": "csharp/worker/core"
13+
}
14+
]
15+
}
16+
]
17+
},
318
{
419
"name": "Go",
520
"frameworks": [

0 commit comments

Comments
 (0)