diff --git a/Workers/TriliumWorker.cs b/Workers/TriliumWorker.cs index b681778..e61c6a1 100644 --- a/Workers/TriliumWorker.cs +++ b/Workers/TriliumWorker.cs @@ -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 _issueChannel; - public TriliumWorker(AppConfigs configs, TriliumService triliumService, Channel issueChannel) + public TriliumWorker(AppConfigs configs, IServiceScopeFactory serviceScopeFactory, + TriliumService triliumService, Channel issueChannel) { _log = Log.ForContext(); _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(); + var unpublishedIssues = await db.GetUnpublishedJiraIssuesAsync(stoppingToken); + if (unpublishedIssues != null) + { + // Publish or update Trilium notes + } + await Task.Delay(10 *1000, stoppingToken); } }