Skip to content
This repository was archived by the owner on Jul 30, 2022. It is now read-only.

Commit 6e8bf80

Browse files
author
Plorence
authored
Merge pull request #27 from bazzi-gg/add_loop_delay_option
반복 딜레이 옵션 추가
2 parents 2856e23 + 4e356ea commit 6e8bf80

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

PlayerGC/HostedServices/PlayerGCHostedService.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using Bazzigg.Database.Context;
22
using Kartrider.Api;
33
using Microsoft.EntityFrameworkCore;
4+
using Microsoft.Extensions.Configuration;
45
using Microsoft.Extensions.Hosting;
56
using Microsoft.Extensions.Logging;
7+
using PlayerGC.Options;
68

79
namespace PlayerGC.HostedServices
810
{
@@ -11,14 +13,16 @@ internal class PlayerGCHostedService : BackgroundService
1113
private readonly ILogger<PlayerGCHostedService> _logger;
1214
private readonly IKartriderApi _kartriderApi;
1315
private readonly IDbContextFactory<AppDbContext> _appDbContextFactory;
14-
16+
private readonly PlayerGCOptions _options = new PlayerGCOptions();
1517
public PlayerGCHostedService(ILogger<PlayerGCHostedService> logger,
16-
IKartriderApi kartriderApi
17-
, IDbContextFactory<AppDbContext> appDbContextFactory)
18+
IKartriderApi kartriderApi,
19+
IDbContextFactory<AppDbContext> appDbContextFactory,
20+
IConfiguration configuration)
1821
{
1922
_logger = logger;
2023
_kartriderApi = kartriderApi;
2124
_appDbContextFactory = appDbContextFactory;
25+
configuration.GetSection(PlayerGCOptions.ConfigurationKey).Bind(_options);
2226
}
2327

2428
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
@@ -47,9 +51,8 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
4751
await appDbContext.SaveChangesAsync(stoppingToken);
4852
_logger.LogInformation($"{player.Nickname}: GC");
4953
}
50-
#if !DEBUG
51-
await Task.Delay(3000, stoppingToken);
52-
#endif
54+
55+
await Task.Delay(TimeSpan.FromMilliseconds(_options.LoopDelay), stoppingToken);
5356
}
5457
}
5558
}

PlayerGC/Options/PlayerGCOptions.cs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace PlayerGC.Options;
2+
3+
public class PlayerGCOptions
4+
{
5+
public const string ConfigurationKey = "PlayerGC";
6+
/// <summary>
7+
/// ms
8+
/// </summary>
9+
public int LoopDelay { get; set; }
10+
}

PlayerGC/appsettings.example.json

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"ConnectionStrings": {
33
"App": "server=localhost;port=3306;database=App;uid=root;password=test"
44
},
5+
"PlayerGC": {
6+
"LoopDelay": 100
7+
},
58
"KartriderApiKey": "NEXON OPEN API",
69
"Logging": {
710
"LogLevel": {

0 commit comments

Comments
 (0)