Files
Partsource/PartSource.Automation/Jobs/ExecuteSsisPackages.cs

56 lines
1.9 KiB
C#

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using PartSource.Automation.Models.Configuration;
using PartSource.Automation.Services;
using Ratermania.Automation.Interfaces;
using System;
using System.Threading.Tasks;
namespace PartSource.Automation.Jobs
{
public class ExecuteSsisPackages : IAutomationJob
{
private readonly EmailService _emailService;
private readonly FtpService _ftpService;
private readonly SsisService _ssisService;
private readonly ILogger<ExecuteSsisPackages> _logger;
// TODO: set from config
private readonly string[] _ssisPackages = { "Parts Price", "Parts Availability" };
public ExecuteSsisPackages(EmailService emailService, FtpService ftpService, SsisService ssisService, ILogger<ExecuteSsisPackages> logger)
{
_ftpService = ftpService;
_emailService = emailService;
_ssisService = ssisService;
_logger = logger;
}
public async Task Run()
{
await Task.Run(() =>
{
foreach (string package in _ssisPackages)
{
try
{
_ftpService.Download($"{package}.txt");
_ssisService.Execute($"{package}.dtsx");
_logger.LogInformation("Execution of SSIS package {package} completed successfully.", package);
}
catch (Exception ex)
{
_logger.LogError(ex, "Execution of SSIS package {package} failed", package);
throw;
}
}
_emailService.Send("Database Updates Complete", "Database updates to support pricing and availability have completed successfully.");
});
}
}
}