From 2e2edc8dacf1981b003d44c30a0bb155bc40d4ec Mon Sep 17 00:00:00 2001 From: smoh Date: Fri, 12 Dec 2025 10:22:08 +0900 Subject: [PATCH] =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EC=9D=B4=EC=8A=88=EB=A5=BC=20?= =?UTF-8?q?=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8A=94=20=EB=85=BC=EB=A6=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Services/AppDbService.cs | 18 ++++++++++++++++++ Workers/TriliumWorker.cs | 14 +++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Services/AppDbService.cs b/Services/AppDbService.cs index 48f73c1..2bf008e 100644 --- a/Services/AppDbService.cs +++ b/Services/AppDbService.cs @@ -203,5 +203,23 @@ public class AppDbService throw; } } + + public async Task> GetUnpublishedJiraIssuesAsync(CancellationToken ct = default) + { + try + { + var unpublishedIssues = await _db.JiraIssues + .Where(ji => ji.Published < ji.Updated) + .ToListAsync(ct); + + _log.Information("Found {count} unpublished Jira issues", unpublishedIssues.Count); + return unpublishedIssues; + } + catch (Exception ex) + { + _log.Error(ex, "Failed to get unpublished Jira issues"); + throw; + } + } #endregion Table: JiraIssues } 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); } }