feat(trades): dynamic settings, IFinlyticLogger, live log streaming, and EF migration

This commit is contained in:
2026-08-15 21:30:19 +02:00
parent 0d370d09e7
commit 57554a9582
9 changed files with 588 additions and 63 deletions
@@ -7,12 +7,13 @@ using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using FinlyticCore.Models.Trades;
using FinlyticCore.Services;
using FinlyticTrades.Database;
using FinlyticTrades.Entities;
using FinlyticTrades.Util;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Parquet.Serialization;
namespace FinlyticTrades.Services;
@@ -25,17 +26,16 @@ public interface IFeedbackExporterEngine
Task ExportFeedbackDataAsync(CancellationToken cancellationToken = default);
}
public class FeedbackExporterEngine : BackgroundService, IFeedbackExporterEngine
{
private readonly IServiceScopeFactory _scopeFactory;
private readonly ILogger<FeedbackExporterEngine> _logger;
private readonly IFinlyticLogger<FeedbackExporterEngine> _finlyticLogger;
private readonly string _feedbackDir;
public FeedbackExporterEngine(IServiceScopeFactory scopeFactory, ILogger<FeedbackExporterEngine> logger)
public FeedbackExporterEngine(IServiceScopeFactory scopeFactory, IFinlyticLogger<FeedbackExporterEngine> finlyticLogger)
{
_scopeFactory = scopeFactory;
_logger = logger;
_finlyticLogger = finlyticLogger;
_feedbackDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data", "feedback");
if (!Directory.Exists(_feedbackDir))
@@ -46,7 +46,7 @@ public class FeedbackExporterEngine : BackgroundService, IFeedbackExporterEngine
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("[{Channel}] Feedback Exporter Engine background service started.", "TradesChannel");
await _finlyticLogger.LogInfoAsync(SettingKeys.TradesChannel, "[FeedbackExporterEngine] Feedback Exporter Engine background service started.");
try
{
@@ -69,7 +69,7 @@ public class FeedbackExporterEngine : BackgroundService, IFeedbackExporterEngine
}
catch (Exception ex)
{
_logger.LogError(ex, "[{Channel}] Error executing feedback exporter job.", "TradesChannel");
await _finlyticLogger.LogErrorAsync(SettingKeys.TradesChannel, ex, "[FeedbackExporterEngine] Error executing feedback exporter job.");
}
try
@@ -82,7 +82,7 @@ public class FeedbackExporterEngine : BackgroundService, IFeedbackExporterEngine
}
}
_logger.LogInformation("[{Channel}] Feedback Exporter Engine background service stopped.", "TradesChannel");
await _finlyticLogger.LogInfoAsync(SettingKeys.TradesChannel, "[FeedbackExporterEngine] Feedback Exporter Engine background service stopped.");
}
/// <summary>
@@ -101,7 +101,7 @@ public class FeedbackExporterEngine : BackgroundService, IFeedbackExporterEngine
if (closedTrades.Count == 0)
{
_logger.LogInformation("[{Channel}] No closed trades available for export.", "TradesChannel");
await _finlyticLogger.LogInfoAsync(SettingKeys.TradesChannel, "[FeedbackExporterEngine] No closed trades available for export.");
return;
}
@@ -184,16 +184,16 @@ public class FeedbackExporterEngine : BackgroundService, IFeedbackExporterEngine
File.Move(parquetTmpPath, parquetPath, overwrite: true);
_logger.LogInformation("[{Channel}] Exported Parquet feedback file for sector '{Sector}' to {ParquetPath}", "TradesChannel", sectorName, parquetPath);
await _finlyticLogger.LogInfoAsync(SettingKeys.TradesChannel, "[FeedbackExporterEngine] Exported Parquet feedback file for sector '{Sector}' to {ParquetPath}", sectorName, parquetPath);
}
catch (Exception ex)
{
_logger.LogWarning(ex, "[{Channel}] Failed to write Parquet file for sector '{Sector}'. JSON file was written successfully.", "TradesChannel", sectorName);
await _finlyticLogger.LogWarningAsync(SettingKeys.TradesChannel, ex, "[FeedbackExporterEngine] Failed to write Parquet file for sector '{Sector}'. JSON file was written successfully.", sectorName);
}
}
_logger.LogInformation("[{Channel}] Successfully exported feedback data for {Count} closed trades across {Sectors} sectors.",
"TradesChannel", closedTrades.Count, groups.Count());
await _finlyticLogger.LogInfoAsync(SettingKeys.TradesChannel, "[FeedbackExporterEngine] Successfully exported feedback data for {Count} closed trades across {Sectors} sectors.",
closedTrades.Count, groups.Count());
}
private static string SanitizeSectorName(string? sector)