diff --git a/PartSource.Automation/Jobs/ProcessWhiFitment.cs b/PartSource.Automation/Jobs/ProcessWhiFitment.cs index 175d6a4..2ab08f0 100644 --- a/PartSource.Automation/Jobs/ProcessWhiFitment.cs +++ b/PartSource.Automation/Jobs/ProcessWhiFitment.cs @@ -51,18 +51,17 @@ namespace PartSource.Automation.Jobs try { string filename = Decompress(fileInfo); - DataTable dataTable = GetDataTable(filename); - string tableName = fileInfo.Name.Substring(0, fileInfo.Name.IndexOf('.')); - _whiSeoService.BulkCopy(_seoDataType, dataTable, tableName); + DataTable dataTable = GetDataTable(filename); + _whiSeoService.BulkCopy(_seoDataType, dataTable, tableName); _logger.LogInformation($"Copied {fileInfo.Name} to the database."); File.Delete(filename); } - catch (Exception ex) + catch (Exception ex) { _logger.LogError($"Failed to write {fileInfo.Name} to the database - {ex.Message}", ex); } @@ -73,7 +72,7 @@ namespace PartSource.Automation.Jobs _logger.LogInformation($"Created fitment table for part group {fitmentTable}."); } - + _whiSeoService.CreateFitmentView(); } @@ -96,8 +95,8 @@ namespace PartSource.Automation.Jobs dataTable.Columns.Add("PartNumber", typeof(string)); dataTable.Columns.Add("BaseVehicleId", typeof(int)); dataTable.Columns.Add("EngineConfigId", typeof(int)); - //dataTable.Columns.Add("Position", typeof(string)); - //dataTable.Columns.Add("NoteText", typeof(string)); + dataTable.Columns.Add("Position", typeof(string)); + dataTable.Columns.Add("NoteText", typeof(string)); using StreamReader reader = new StreamReader(filename); string line = reader.ReadLine(); // Burn the header row @@ -122,7 +121,7 @@ namespace PartSource.Automation.Jobs && int.TryParse(columns[5], out int baseVehicleId) && int.TryParse(columns[6], out int engineConfigId)) { - dataTable.Rows.Add(new object[] { lineCode, partNumber, baseVehicleId, engineConfigId }); //, position, noteText }); + dataTable.Rows.Add(new object[] { lineCode, partNumber, baseVehicleId, engineConfigId, position, noteText }); } } diff --git a/PartSource.Automation/Jobs/TestJob.cs b/PartSource.Automation/Jobs/TestJob.cs index 2a45b64..3c25313 100644 --- a/PartSource.Automation/Jobs/TestJob.cs +++ b/PartSource.Automation/Jobs/TestJob.cs @@ -5,22 +5,25 @@ using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.Logging; +using PartSource.Automation.Services; namespace PartSource.Automation.Jobs { public class TestJob : IAutomationJob { private readonly ILogger _logger; + private readonly EmailService _emailService; - public TestJob(ILogger logger) + public TestJob(ILogger logger, EmailService emailService) { _logger = logger; + _emailService = emailService; } #pragma warning disable CS1998, CA1303 public async Task Run() { - await Task.Delay(5000); + // _emailService.Send("Automation Test Message", "This is a test email from the automation server. If this message was in your spam folder, whitelist the address that sent this email."); _logger.LogInformation("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc scelerisque congue euismod. Curabitur enim eros, sollicitudin ac purus eget, dignissim mattis augue. In quam sapien, tincidunt et elementum vitae, interdum vitae sem."); _logger.LogWarning("Praesent feugiat sapien non suscipit faucibus. Mauris fermentum ut augue a feugiat. Integer felis sem, laoreet et augue at, finibus maximus ex. Fusce sit amet erat non tortor porta condimentum condimentum quis ipsum."); diff --git a/PartSource.Automation/Jobs/UpdateFitment.cs b/PartSource.Automation/Jobs/UpdateFitment.cs index c8eef00..e820fd5 100644 --- a/PartSource.Automation/Jobs/UpdateFitment.cs +++ b/PartSource.Automation/Jobs/UpdateFitment.cs @@ -42,7 +42,7 @@ namespace PartSource.Automation.Jobs try { - products = await _shopifyClient.Products.Get(new Dictionary { { "limit", 250 } }); + products = await _shopifyClient.Products.Get(new Dictionary { { "limit", 250 } });//, {"product_type", "CA142-SC130-FL13029_Certified Brake Pads" } }); } catch (Exception ex) @@ -51,10 +51,6 @@ namespace PartSource.Automation.Jobs throw; } - IList parts = await _partSourceContext.ImportData - .Where(i => i.UpdatedAt <= DateTime.Now.AddDays(-7)) - .ToListAsync(); - int i = 1; while (products != null && products.Any()) @@ -65,7 +61,7 @@ namespace PartSource.Automation.Jobs try { - importData = parts.FirstOrDefault(parts => parts.ShopifyId == product.Id); + importData = await _partSourceContext.ImportData.FirstOrDefaultAsync(parts => parts.ShopifyId == product.Id); if (importData == null) { diff --git a/PartSource.Automation/Jobs/UpdatePricing.cs b/PartSource.Automation/Jobs/UpdatePricing.cs index d5f917f..e38c2b5 100644 --- a/PartSource.Automation/Jobs/UpdatePricing.cs +++ b/PartSource.Automation/Jobs/UpdatePricing.cs @@ -38,6 +38,7 @@ namespace PartSource.Automation.Jobs try { products = await _shopifyClient.Products.Get(new Dictionary { { "limit", 250 } }); + prices = await _partSourceContext.PartPrices.ToListAsync(); } @@ -120,7 +121,7 @@ namespace PartSource.Automation.Jobs } } - _emailService.Send("Update Pricing Completed", $"{updateCount} prices were updated"); + _emailService.Send("Pricing Update Completed", $"The pricing update has completed. Total updated: {updateCount}"); } } } \ No newline at end of file diff --git a/PartSource.Automation/Program.cs b/PartSource.Automation/Program.cs index 2c5b64b..0e06edb 100644 --- a/PartSource.Automation/Program.cs +++ b/PartSource.Automation/Program.cs @@ -70,25 +70,28 @@ namespace PartSource.Automation { options.HasBaseInterval(new TimeSpan(0, 15, 0)) .HasMaxFailures(5) + //.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)) + //.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)) // .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(26)) - ) - .HasJob(options => options.HasInterval(new TimeSpan(24, 0, 0)) - .HasDependency() - .StartsAt(DateTime.Today.AddHours(27) - ) + // .HasJob(options => options.HasInterval(new TimeSpan(24, 0, 0)) + // .StartsAt(DateTime.Today.AddHours(26)) + // ) + // .HasJob(options => options.HasInterval(new TimeSpan(24, 0, 0)) + // .HasDependency() + // .StartsAt(DateTime.Today.AddHours(27) + // ) ); - //.AddApiServer(); + //.AddApiServer(); }) .AddSingleton() @@ -101,10 +104,10 @@ namespace PartSource.Automation }) .ConfigureLogging((builder, logging) => { - //logging.AddEventLog(); + logging.AddEventLog(); logging.AddConsole(); - // logging.AddProvider(new AutomationLoggerProvider()); + // logging.AddProvider(new AutomationLoggerProvider()); }); } } diff --git a/PartSource.Automation/Services/EmailService.cs b/PartSource.Automation/Services/EmailService.cs index f5fa3d1..44ae76e 100644 --- a/PartSource.Automation/Services/EmailService.cs +++ b/PartSource.Automation/Services/EmailService.cs @@ -39,7 +39,7 @@ namespace PartSource.Automation.Services mailMessage.To.Add(address); } - smtpClient.Send(mailMessage); + // smtpClient.Send(mailMessage); } public void Send(string to, string subject, string body) @@ -62,7 +62,7 @@ namespace PartSource.Automation.Services mailMessage.To.Add(to); } - smtpClient.Send(mailMessage); + // smtpClient.Send(mailMessage); } } } diff --git a/PartSource.Automation/Services/WhiSeoService.cs b/PartSource.Automation/Services/WhiSeoService.cs index 264f972..b194220 100644 --- a/PartSource.Automation/Services/WhiSeoService.cs +++ b/PartSource.Automation/Services/WhiSeoService.cs @@ -86,6 +86,7 @@ namespace PartSource.Automation.Services connection.Open(); using SqlCommand command = new SqlCommand($"exec CreateFitmentTable @tableName = '{tableName}'", connection); + command.CommandTimeout = 1800; command.ExecuteNonQuery(); } diff --git a/PartSource.Automation/appsettings.json b/PartSource.Automation/appsettings.json index 86768e4..461dded 100644 --- a/PartSource.Automation/appsettings.json +++ b/PartSource.Automation/appsettings.json @@ -4,10 +4,8 @@ "PartSourceDatabase": "Server=tcp:ps-whi.database.windows.net,1433;Initial Catalog=ps-whi-stage;Persist Security Info=False;User ID=ps-whi;Password=9-^*N5dw!6:|.5Q;MultipleActiveResultSets=True;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" }, "emailConfiguration": { - "From": "alerts@ps-automation.eastus2.cloudapp.azure.com", - // "To": "tom@soundpress.com,Anas.Bajwa@Partsource.ca", - "To": "tom@tomraterman.com", + "To": "tom@soundpress.com,Anas.Bajwa@Partsource.ca,josh@soundpress.com,alex.au@partsource.ca,michael.massara@partsource.ca", "SmtpHost": "localhost" }, "FtpServers": { @@ -37,6 +35,11 @@ "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" + }, + "EventLog": { + "LogLevel": { + "default": "Information" + } } } } \ No newline at end of file