DB 서비스 사용 방식 변경
This commit is contained in:
@@ -11,13 +11,16 @@ public class TriliumWorker : BackgroundService
|
||||
{
|
||||
private readonly Serilog.ILogger _log;
|
||||
private readonly AppConfigs _config;
|
||||
private readonly IServiceScopeFactory _scopeFactory; // Singleton services cannot directly inject Scoped services.
|
||||
private readonly TriliumService _triliumService;
|
||||
private readonly Channel<Issue> _issueChannel;
|
||||
|
||||
public TriliumWorker(AppConfigs configs, TriliumService triliumService, Channel<Issue> issueChannel)
|
||||
public TriliumWorker(AppConfigs configs, IServiceScopeFactory serviceScopeFactory,
|
||||
TriliumService triliumService, Channel<Issue> issueChannel)
|
||||
{
|
||||
_log = Log.ForContext<TriliumWorker>();
|
||||
_config = configs;
|
||||
_scopeFactory = serviceScopeFactory;
|
||||
_triliumService = triliumService;
|
||||
_issueChannel = issueChannel;
|
||||
}
|
||||
@@ -27,6 +30,15 @@ public class TriliumWorker : BackgroundService
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
_log.Debug("Worker running at: {time}", DateTimeOffset.Now);
|
||||
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDbService>();
|
||||
var unpublishedIssues = await db.GetUnpublishedJiraIssuesAsync(stoppingToken);
|
||||
if (unpublishedIssues != null)
|
||||
{
|
||||
// Publish or update Trilium notes
|
||||
}
|
||||
|
||||
await Task.Delay(10 *1000, stoppingToken);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user