Compare commits

...

8 Commits

Author SHA1 Message Date
44e87f1334 잡 기반 구현 2025-12-07 05:29:06 +09:00
61d43ef61e 메인 루프 구조 2025-12-07 04:40:54 +09:00
3261e85b33 간단한 루프 추가 2025-12-07 04:30:11 +09:00
ed36f4e747 싱글톤 클래스 추가 2025-12-07 04:14:03 +09:00
5e673375d4 예외 발생시 에러코드 출력 가능하도록 수정 2025-12-07 04:13:40 +09:00
8458995132 테스트 코드 제거 2025-12-07 03:52:48 +09:00
042f633603 간단한 API 테스트 2025-10-15 02:27:39 +09:00
6142899fed 테스트 프로젝트 추가 2025-10-15 02:27:29 +09:00
8 changed files with 218 additions and 5 deletions

View File

@@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WarhoundConsole", "Warhound
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WarhoundLib", "WarhoundLib\WarhoundLib.csproj", "{7E3472E9-86E9-4032-826C-0DA805C2EBCE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WarhoundTest", "WarhoundTest\WarhoundTest.csproj", "{D22BEA2A-08E9-498A-A087-FEFB8FA2AD08}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
{7E3472E9-86E9-4032-826C-0DA805C2EBCE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7E3472E9-86E9-4032-826C-0DA805C2EBCE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E3472E9-86E9-4032-826C-0DA805C2EBCE}.Release|Any CPU.Build.0 = Release|Any CPU
{D22BEA2A-08E9-498A-A087-FEFB8FA2AD08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D22BEA2A-08E9-498A-A087-FEFB8FA2AD08}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D22BEA2A-08E9-498A-A087-FEFB8FA2AD08}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D22BEA2A-08E9-498A-A087-FEFB8FA2AD08}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

61
WarhoundConsole/Job.cs Normal file
View File

@@ -0,0 +1,61 @@
namespace WarhoundConsole
{
public abstract class Job
{
private readonly TimeSpan interval;
private Task task;
private DateTime lastExecutedTime;
public Job(TimeSpan interval)
{
if (interval <= TimeSpan.Zero)
{
throw new ArgumentOutOfRangeException(nameof(interval));
}
this.interval = interval;
this.task = Task.CompletedTask;
this.lastExecutedTime = DateTime.MinValue;
}
public bool TryExecute()
{
try
{
var now = DateTime.Now;
if (now - this.lastExecutedTime < this.interval)
{
return false;
}
if (!this.task.IsCompleted)
{
// 이 경우 로그를 출력하도록 하고, 타이밍을 조절해야한다.
//Console.WriteLine($"Job skipped at {DateTime.Now}");
return false;
}
this.lastExecutedTime = now;
this.task = Task.Run(async () =>
{
await this.Execute();
});
}
catch (Exception e)
{
Console.WriteLine(e);
}
return true;
}
protected abstract Task Execute();
public void Wait()
{
this.task?.Wait();
}
}
}

View File

@@ -1,10 +1,66 @@
namespace WarhoundConsole
using System.Diagnostics;
namespace WarhoundConsole
{
internal class Program
public class Program
{
static void Main(string[] args)
public static int Main(string[] args)
{
Console.WriteLine("Hello, World!");
try
{
MainInternal(args);
}
catch (Exception e)
{
Console.WriteLine(e);
return -1;
}
return 0;
}
private static void MainInternal(string[] args)
{
Singleton.I.Initialize(new());
var jobs = new List<Job>();
var sw = Stopwatch.StartNew();
while (!Singleton.I.ExitRequested)
{
try
{
sw.Restart();
foreach (var job in jobs)
{
_ = job.TryExecute();
}
sw.Stop();
const int targetFrameTimeMs = 10;
if (sw.Elapsed.Milliseconds < targetFrameTimeMs)
{
Thread.Sleep(targetFrameTimeMs - sw.Elapsed.Milliseconds);
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
foreach (var job in jobs)
{
job.Wait();
}
Shutdown();
}
private static void Shutdown()
{
// DO SOMETHING
}
}
}

View File

@@ -0,0 +1,57 @@
namespace WarhoundConsole
{
public sealed class Singleton
{
public sealed class InitializeParams
{
// FILL SOMETHING
}
public static Singleton I => i ??= new();
private static Singleton? i = null;
private bool isInitialized;
public bool ExitRequested { get; private set; }
private Singleton()
{
this.isInitialized = false;
this.ExitRequested = false;
}
public bool Initialize(InitializeParams initializeParams)
{
try
{
if (this.isInitialized)
{
throw new InvalidOperationException("이미 초기화된 싱글톤");
}
if (initializeParams == null)
{
throw new ArgumentNullException(nameof(initializeParams));
}
this.InitializeInternal(initializeParams);
}
finally
{
this.isInitialized = true;
}
return true;
}
private void InitializeInternal(InitializeParams initializeParams)
{
// DO SOMETHING
}
public void Exit()
{
this.ExitRequested = true;
}
}
}

View File

@@ -8,7 +8,9 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\WarhoundLib\WarhoundLib.csproj" />
<ProjectReference Include="..\WarhoundLib\WarhoundLib.csproj" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.4" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1 @@
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]

11
WarhoundTest/Test1.cs Normal file
View File

@@ -0,0 +1,11 @@
namespace WarhoundTest
{
[TestClass]
public sealed class Test1
{
[TestMethod]
public void TestMethod1()
{
}
}
}

View File

@@ -0,0 +1,19 @@
<Project Sdk="MSTest.Sdk/3.6.4">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<!--
Displays error on console in addition to the log file. Note that this feature comes with a performance impact.
For more information, visit https://learn.microsoft.com/dotnet/core/testing/unit-testing-platform-integration-dotnet-test#show-failure-per-test
-->
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\WarhoundLib\WarhoundLib.csproj" />
</ItemGroup>
</Project>