업데이트 필요한 이슈를 가져오는 논리 추가.
This commit is contained in:
@@ -203,5 +203,23 @@ public class AppDbService
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<JiraIssue>> 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
|
#endregion Table: JiraIssues
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,16 @@ public class TriliumWorker : BackgroundService
|
|||||||
{
|
{
|
||||||
private readonly Serilog.ILogger _log;
|
private readonly Serilog.ILogger _log;
|
||||||
private readonly AppConfigs _config;
|
private readonly AppConfigs _config;
|
||||||
|
private readonly IServiceScopeFactory _scopeFactory; // Singleton services cannot directly inject Scoped services.
|
||||||
private readonly TriliumService _triliumService;
|
private readonly TriliumService _triliumService;
|
||||||
private readonly Channel<Issue> _issueChannel;
|
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>();
|
_log = Log.ForContext<TriliumWorker>();
|
||||||
_config = configs;
|
_config = configs;
|
||||||
|
_scopeFactory = serviceScopeFactory;
|
||||||
_triliumService = triliumService;
|
_triliumService = triliumService;
|
||||||
_issueChannel = issueChannel;
|
_issueChannel = issueChannel;
|
||||||
}
|
}
|
||||||
@@ -27,6 +30,15 @@ public class TriliumWorker : BackgroundService
|
|||||||
while (!stoppingToken.IsCancellationRequested)
|
while (!stoppingToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
_log.Debug("Worker running at: {time}", DateTimeOffset.Now);
|
_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);
|
await Task.Delay(10 *1000, stoppingToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user