This is it. Don't get scared now. (Converted to Ratermania.Automation)

This commit is contained in:
2021-01-27 21:04:53 -05:00
parent b0935e9214
commit e1be26d798
29 changed files with 1694 additions and 1025 deletions

View File

@@ -1,8 +1,9 @@
using PartSource.Automation.Jobs.Interfaces;
using PartSource.Automation.Models;
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.Collections.Generic;
using System.Threading.Tasks;
namespace PartSource.Automation.Jobs
@@ -11,43 +12,42 @@ namespace PartSource.Automation.Jobs
{
private readonly FtpService _ftpService;
private readonly SsisService _ssisService;
private readonly ILogger<ExecuteSsisPackages> _logger;
// TODO: set from config
private readonly string[] _ssisPackages = { "Parts Availability", "Parts Price" };
public ExecuteSsisPackages(FtpService ftpService, SsisService ssisService)
public ExecuteSsisPackages(IConfiguration configuration, SsisService ssisService, ILogger<ExecuteSsisPackages> logger)
{
_ftpService = ftpService;
FtpConfiguration ftpConfiguration = configuration.GetSection("FtpServers:AzureConfiguration").Get<FtpConfiguration>();
_ftpService = new FtpService(ftpConfiguration);
_ssisService = ssisService;
_logger = logger;
}
public async Task<AutomationJobResult> Run()
public async Task Run()
{
IList<string> updatedPackages = new List<string>();
IList<string> failedPackages = new List<string>();
foreach (string package in _ssisPackages)
await Task.Run(() =>
{
try
foreach (string package in _ssisPackages)
{
_ftpService.Download($"{package}.txt");
_ssisService.Execute($"{package}.dtsx");
try
{
_ftpService.Download($"{package}.txt");
_ssisService.Execute($"{package}.dtsx");
updatedPackages.Add(package);
_logger.LogInformation($"Execution of SSIS package {package} completed successfully.");
}
catch (Exception ex)
{
_logger.LogError($"Execution of SSIS package {package} failed.", ex);
throw;
}
}
catch (Exception ex)
{
failedPackages.Add(package);
// TODO: Log
}
}
return new AutomationJobResult
{
Message = $"Updated Packages: {string.Join(',', updatedPackages)} \n Failed Packages: {string.Join(',', failedPackages)}",
IsSuccess = failedPackages.Count == 0
};
});
}
}
}