Skip to content

Commit

Permalink
Merge pull request #43 from the9ball/chore/console_multiple_worker
Browse files Browse the repository at this point in the history
feat: Create multiple worker project
  • Loading branch information
hadashiA authored Mar 21, 2024
2 parents 5de6f33 + adc12b4 commit 0c5d71a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 2 deletions.
7 changes: 7 additions & 0 deletions DFrame.sln
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DFrame.RestSdk", "src\DFram
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MinimumGrpc", "sandbox\MinimumGrpc\MinimumGrpc.csproj", "{C7BBF6FF-BFB2-4791-AA0D-36B9BFF84C9A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleMultipleWorker", "sandbox\ConsoleMultipleWorker\ConsoleMultipleWorker.csproj", "{1BFEF842-0BD4-4249-818A-09DD5E151434}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -98,6 +100,10 @@ Global
{C7BBF6FF-BFB2-4791-AA0D-36B9BFF84C9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7BBF6FF-BFB2-4791-AA0D-36B9BFF84C9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7BBF6FF-BFB2-4791-AA0D-36B9BFF84C9A}.Release|Any CPU.Build.0 = Release|Any CPU
{1BFEF842-0BD4-4249-818A-09DD5E151434}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1BFEF842-0BD4-4249-818A-09DD5E151434}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1BFEF842-0BD4-4249-818A-09DD5E151434}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1BFEF842-0BD4-4249-818A-09DD5E151434}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -112,6 +118,7 @@ Global
{680A7D0B-FBC2-4826-AEC8-2F63B30AC622} = {DDD04377-167A-4FDC-90D5-01EDCB7BA465}
{F7BC52D7-6D75-4980-8C2D-31408701A3A4} = {DDD04377-167A-4FDC-90D5-01EDCB7BA465}
{C7BBF6FF-BFB2-4791-AA0D-36B9BFF84C9A} = {DDD04377-167A-4FDC-90D5-01EDCB7BA465}
{1BFEF842-0BD4-4249-818A-09DD5E151434} = {DDD04377-167A-4FDC-90D5-01EDCB7BA465}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {77245B01-4128-4759-BF61-CC223FAA2E01}
Expand Down
7 changes: 7 additions & 0 deletions DFrame.sln.startup.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
"ConsoleController": {},
"MinimalEcho": {}
}
},
"ConsoleController + ConsoleMultipleWorker + MinimalEcho": {
"Projects": {
"ConsoleMultipleWorker": {},
"ConsoleController": {},
"MinimalEcho": {}
}
}
}
}
14 changes: 14 additions & 0 deletions sandbox/ConsoleMultipleWorker/ConsoleMultipleWorker.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ConsoleWorker\ConsoleWorker.csproj" />
</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions sandbox/ConsoleMultipleWorker/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using ConsoleAppFramework;
using System.Diagnostics;

await ConsoleApp.RunAsync(args, run);

static async Task run([Option(0)] int workerCount = 10)
{
Debug.Assert(workerCount > 0);

Task[] workerTasks = new Task[workerCount];
for (int i = 0; i < workerCount; i++)
{
workerTasks[i] = ConsoleWorker.Program.Main([]);
}
await Task.WhenAll(workerTasks);
}

12 changes: 10 additions & 2 deletions sandbox/ConsoleWorker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

await Host.CreateDefaultBuilder(args)
.RunDFrameWorkerAsync("http://localhost:7313"); // http/2 address to connect controller
namespace ConsoleWorker;

public static class Program
{
public static async Task Main(string[] args)
{
await Host.CreateDefaultBuilder(args)
.RunDFrameWorkerAsync("http://localhost:7313"); // http/2 address to connect controller
}
}

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously

Expand Down
2 changes: 2 additions & 0 deletions sandbox/ConsoleWorker/Workloads.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using MessagePack;
using Microsoft.Extensions.Logging;

namespace ConsoleWorker;

[Workload("myworkload")]
public class TrialWorkload : Workload
{
Expand Down

0 comments on commit 0c5d71a

Please sign in to comment.