1
1
using Bazzigg . Database . Context ;
2
2
using Kartrider . Api ;
3
3
using Microsoft . EntityFrameworkCore ;
4
+ using Microsoft . Extensions . Configuration ;
4
5
using Microsoft . Extensions . Hosting ;
5
6
using Microsoft . Extensions . Logging ;
7
+ using PlayerGC . Options ;
6
8
7
9
namespace PlayerGC . HostedServices
8
10
{
@@ -11,14 +13,16 @@ internal class PlayerGCHostedService : BackgroundService
11
13
private readonly ILogger < PlayerGCHostedService > _logger ;
12
14
private readonly IKartriderApi _kartriderApi ;
13
15
private readonly IDbContextFactory < AppDbContext > _appDbContextFactory ;
14
-
16
+ private readonly PlayerGCOptions _options = new PlayerGCOptions ( ) ;
15
17
public PlayerGCHostedService ( ILogger < PlayerGCHostedService > logger ,
16
- IKartriderApi kartriderApi
17
- , IDbContextFactory < AppDbContext > appDbContextFactory )
18
+ IKartriderApi kartriderApi ,
19
+ IDbContextFactory < AppDbContext > appDbContextFactory ,
20
+ IConfiguration configuration )
18
21
{
19
22
_logger = logger ;
20
23
_kartriderApi = kartriderApi ;
21
24
_appDbContextFactory = appDbContextFactory ;
25
+ configuration . GetSection ( PlayerGCOptions . ConfigurationKey ) . Bind ( _options ) ;
22
26
}
23
27
24
28
protected override async Task ExecuteAsync ( CancellationToken stoppingToken )
@@ -47,9 +51,8 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
47
51
await appDbContext . SaveChangesAsync ( stoppingToken ) ;
48
52
_logger . LogInformation ( $ "{ player . Nickname } : GC") ;
49
53
}
50
- #if ! DEBUG
51
- await Task . Delay ( 3000 , stoppingToken ) ;
52
- #endif
54
+
55
+ await Task . Delay ( TimeSpan . FromMilliseconds ( _options . LoopDelay ) , stoppingToken ) ;
53
56
}
54
57
}
55
58
}
0 commit comments