diff --git a/PartSource.Api/PartSource.Api.csproj b/PartSource.Api/PartSource.Api.csproj index b081ba9..39087ef 100644 --- a/PartSource.Api/PartSource.Api.csproj +++ b/PartSource.Api/PartSource.Api.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net6.0 f9e2fd37-0f2d-4e3a-955a-8e49a16fce1c Debug;Release;Also Debug @@ -12,11 +12,14 @@ - + + + + - + diff --git a/PartSource.Automation/Jobs/ExecuteSsisPackages.cs b/PartSource.Automation/Jobs/ExecuteSsisPackages.cs index 6472727..a821245 100644 --- a/PartSource.Automation/Jobs/ExecuteSsisPackages.cs +++ b/PartSource.Automation/Jobs/ExecuteSsisPackages.cs @@ -8,46 +8,48 @@ using System.Threading.Tasks; namespace PartSource.Automation.Jobs { - public class ExecuteSsisPackages : IAutomationJob - { - private readonly FtpService _ftpService; - private readonly SsisService _ssisService; - private readonly ILogger _logger; + public class ExecuteSsisPackages : IAutomationJob + { + private readonly EmailService _emailService; + private readonly FtpService _ftpService; + private readonly SsisService _ssisService; + private readonly ILogger _logger; - // TODO: set from config - private readonly string[] _ssisPackages = { "Parts Availability" }; + // TODO: set from config + private readonly string[] _ssisPackages = { "Parts Price", "Parts Availability" }; - public ExecuteSsisPackages(IConfiguration configuration, SsisService ssisService, ILogger logger) - { - FtpConfiguration ftpConfiguration = configuration.GetSection("FtpServers:AzureConfiguration").Get(); + public ExecuteSsisPackages(EmailService emailService, FtpService ftpService, SsisService ssisService, ILogger logger) + { + _ftpService = ftpService; + _emailService = emailService; + _ssisService = ssisService; + _logger = logger; + } - _ftpService = new FtpService(ftpConfiguration); - _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"); - 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); + } - _logger.LogInformation($"Execution of SSIS package {package} completed successfully."); - } + catch (Exception ex) + { + _logger.LogError(ex, "Execution of SSIS package {package} failed", package); - catch (Exception ex) - { - _logger.LogError($"Execution of SSIS package {package} failed.", ex); + throw; + } + } - throw; - } - } - }); - } - } + _emailService.Send("Database Updates Complete", "Database updates to support pricing and availability have completed successfully."); + }); + } + } } diff --git a/PartSource.Automation/PartSource.Automation.csproj b/PartSource.Automation/PartSource.Automation.csproj index fb6b61b..bac6b3f 100644 --- a/PartSource.Automation/PartSource.Automation.csproj +++ b/PartSource.Automation/PartSource.Automation.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + net6.0 Debug;Release;Also Debug diff --git a/PartSource.Automation/Program.cs b/PartSource.Automation/Program.cs index 3a9e150..10afc63 100644 --- a/PartSource.Automation/Program.cs +++ b/PartSource.Automation/Program.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using PartSource.Automation.Jobs; using PartSource.Automation.Jobs.POC; +using PartSource.Automation.Models.Configuration; using PartSource.Automation.Services; using PartSource.Data; using PartSource.Data.AutoMapper; @@ -20,111 +21,96 @@ using System.Threading.Tasks; namespace PartSource.Automation { - class Program - { - static async Task Main(string[] args){ - try - { - using IHost host = CreateHostBuilder().Build(); + class Program + { + static async Task Main(string[] args) + { + try + { + using IHost host = CreateHostBuilder().Build(); - await host.StartAsync(); - } + await host.StartAsync(); + } - catch (Exception ex) - { - Console.WriteLine(ex.ToString()); - throw; - } - } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + throw; + } + } - private static IHostBuilder CreateHostBuilder() - { - return Host.CreateDefaultBuilder() - .ConfigureAppConfiguration(builder => - { - string environment = Environment.GetEnvironmentVariable("AUTOMATION_ENVIRONMENT"); + private static IHostBuilder CreateHostBuilder() + { + return Host.CreateDefaultBuilder() + .ConfigureAppConfiguration(builder => + { + string environment = Environment.GetEnvironmentVariable("AUTOMATION_ENVIRONMENT"); - builder.SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) - .AddJsonFile($"appsettings.{environment}.json", optional: true, reloadOnChange: true); - }) - .ConfigureServices((builder, services) => - { - services.AddDbContext(options => - options.UseSqlServer(builder.Configuration.GetConnectionString("PartSourceDatabase"), opts => opts.EnableRetryOnFailure()) - ) + builder.SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddJsonFile($"appsettings.{environment}.json", optional: true, reloadOnChange: true); + }) + .ConfigureServices((builder, services) => + { + services.AddDbContext(options => + options.UseSqlServer(builder.Configuration.GetConnectionString("PartSourceDatabase"), opts => opts.EnableRetryOnFailure()) + ) - .AddDbContext(options => - options.UseSqlServer(builder.Configuration.GetConnectionString("FitmentDatabase"), opts => - { - opts.EnableRetryOnFailure(); - opts.CommandTimeout(600); - }) - ) + .AddDbContext(options => + options.UseSqlServer(builder.Configuration.GetConnectionString("FitmentDatabase"), opts => + { + opts.EnableRetryOnFailure(); + opts.CommandTimeout(600); + }) + ) - .AddShopify(options => - { - options.ApiKey = builder.Configuration["Shopify:ApiKey"]; - options.ApiSecret = builder.Configuration["Shopify:ApiSecret"]; - options.ApiVersion = "2020-01"; - options.ShopDomain = builder.Configuration["Shopify:ShopDomain"]; + .AddShopify(options => + { + options.ApiKey = builder.Configuration["Shopify:ApiKey"]; + options.ApiSecret = builder.Configuration["Shopify:ApiSecret"]; + options.ApiVersion = "2021-01"; + options.ShopDomain = builder.Configuration["Shopify:ShopDomain"]; - //options.ApiKey = "9a533dad460321c6ce8f30bf5b8691ed"; - //options.ApiSecret = "dc9e28365d9858e544d57ac7af43fee7"; - //options.ApiVersion = "2020-01"; - //options.ShopDomain = "dev-partsource.myshopify.com"; - }) + //options.ApiKey = "9a533dad460321c6ce8f30bf5b8691ed"; + //options.ApiSecret = "dc9e28365d9858e544d57ac7af43fee7"; + //options.ApiVersion = "2020-01"; + //options.ShopDomain = "dev-partsource.myshopify.com"; + }) - .AddAutomation(options => - { - options.HasBaseInterval(new TimeSpan(0, 15, 0)) - .HasMaxFailures(1) - //.HasJob(options => options.HasInterval(new TimeSpan(7, 0, 0, 0))); - // - //.HasJob(options => options.HasInterval(new TimeSpan(24, 0, 0))) - .HasJob(options => options.HasInterval(new TimeSpan(24, 0, 0))); - //.HasJob(options => options.HasInterval(new TimeSpan(24, 0, 0)) - //.HasDependency() - //.HasJob(options => options.HasInterval(new TimeSpan(24, 0, 0))); - //.HasJob(options => options.HasInterval(new TimeSpan(24, 0, 0)) - // .HasDependency() - // .HasDependency() - // .HasDependency() - // .StartsAt(DateTime.Today.AddHours(8)) - //) ; - //.HasJob(options => options.HasInterval(new TimeSpan(24, 0, 0)) - // .StartsAt(DateTime.Parse("2021-04-01 08:00:00")) - //) - //.HasJob(options => - //options.HasInterval(new TimeSpan(24, 0, 0)) - // .StartsAt(DateTime.Today.AddHours(5)) - // ); - //.StartsAt(DateTime.Today.AddHours(26)) - //) - //.HasJob(options => options.HasInterval(new TimeSpan(24, 0, 0)) - //.HasDependency() - //.StartsAt(DateTime.Today.AddHours(27) - //) - //); - //.AddApiServer(); - }) + .AddAutomation(options => + { + options.HasBaseInterval(new TimeSpan(0, 15, 0)) + .HasMaxFailures(3) + .HasJob(options => + options.HasInterval(new TimeSpan(24, 0, 0)) + .StartsAt(DateTime.Today.AddHours(26)) + ) + .HasJob(options => + options.HasInterval(new TimeSpan(24, 0, 0)) + .StartsAt(DateTime.Today.AddHours(27)) + .HasDependency() + ); + //.AddApiServer(); + }) - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() + .AddSingleton(builder.Configuration.GetSection("FtpServers:AzureConfiguration").Get()) + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() - .AddAutoMapper(typeof(PartSourceProfile)); - }) - .ConfigureLogging((builder, logging) => - { - logging.AddEventLog(); - logging.AddConsole(); + .AddAutoMapper(typeof(PartSourceProfile)); + }) + .ConfigureLogging((builder, logging) => + { + logging.AddEventLog(); + logging.AddConsole(); - // logging.AddProvider(new AutomationLoggerProvider()); - }); - } - } + // logging.AddProvider(new AutomationLoggerProvider()); + }); + } + } } diff --git a/PartSource.Data/PartSource.Data.csproj b/PartSource.Data/PartSource.Data.csproj index 4330898..668f275 100644 --- a/PartSource.Data/PartSource.Data.csproj +++ b/PartSource.Data/PartSource.Data.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net6.0 Debug;Release;Also Debug diff --git a/PartSource.Services/PartSource.Services.csproj b/PartSource.Services/PartSource.Services.csproj index 6c9dd00..d95d776 100644 --- a/PartSource.Services/PartSource.Services.csproj +++ b/PartSource.Services/PartSource.Services.csproj @@ -1,10 +1,16 @@  - netcoreapp3.1 + net6.0 Debug;Release;Also Debug + + + + + + @@ -21,8 +27,4 @@ - - - -