Various changes

This commit is contained in:
2021-07-31 11:10:33 -04:00
parent 962ad3383f
commit fb6dbdfaa7
8 changed files with 42 additions and 36 deletions

View File

@@ -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 });
}
}

View File

@@ -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<TestJob> _logger;
private readonly EmailService _emailService;
public TestJob(ILogger<TestJob> logger)
public TestJob(ILogger<TestJob> 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.");

View File

@@ -42,7 +42,7 @@ namespace PartSource.Automation.Jobs
try
{
products = await _shopifyClient.Products.Get(new Dictionary<string, object> { { "limit", 250 } });
products = await _shopifyClient.Products.Get(new Dictionary<string, object> { { "limit", 250 } });//, {"product_type", "CA142-SC130-FL13029_Certified Brake Pads" } });
}
catch (Exception ex)
@@ -51,10 +51,6 @@ namespace PartSource.Automation.Jobs
throw;
}
IList<ImportData> 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)
{

View File

@@ -38,6 +38,7 @@ namespace PartSource.Automation.Jobs
try
{
products = await _shopifyClient.Products.Get(new Dictionary<string, object> { { "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}");
}
}
}

View File

@@ -70,25 +70,28 @@ namespace PartSource.Automation
{
options.HasBaseInterval(new TimeSpan(0, 15, 0))
.HasMaxFailures(5)
//.HasJob<TestJob>(options => options.HasInterval(new TimeSpan(7, 0, 0, 0)));
//
//.HasJob<SyncronizeProducts>(options => options.HasInterval(new TimeSpan(24, 0, 0))
// .HasJob<ProcessWhiFitment>(options => options.HasInterval(new TimeSpan(24, 0, 0))
//.HasJob<UpdateFitment>(options => options.HasInterval(new TimeSpan(24, 0, 0))
//.HasJob<SyncronizeProducts>(options => options.HasInterval(new TimeSpan(24, 0, 0)))
.HasJob<ProcessWhiFitment>(options => options.HasInterval(new TimeSpan(24, 0, 0))
// .HasDependency<SyncronizeProducts>()
// .HasJob<UpdateFitment>(options => options.HasInterval(new TimeSpan(24, 0, 0))
// .HasDependency<ProcessWhiFitment>()
//.HasDependency<SyncronizeProducts>()
// .StartsAt(DateTime.Today.AddHours(8))
//)
//) ;
//.HasJob<StatusCheck>(options => options.HasInterval(new TimeSpan(24, 0, 0))
// .StartsAt(DateTime.Parse("2021-04-01 08:00:00"))
//)
.HasJob<ExecuteSsisPackages>(options => options.HasInterval(new TimeSpan(24, 0, 0))
.StartsAt(DateTime.Today.AddHours(26))
)
.HasJob<UpdatePricing>(options => options.HasInterval(new TimeSpan(24, 0, 0))
.HasDependency<ExecuteSsisPackages>()
.StartsAt(DateTime.Today.AddHours(27)
)
// .HasJob<ExecuteSsisPackages>(options => options.HasInterval(new TimeSpan(24, 0, 0))
// .StartsAt(DateTime.Today.AddHours(26))
// )
// .HasJob<UpdatePricing>(options => options.HasInterval(new TimeSpan(24, 0, 0))
// .HasDependency<ExecuteSsisPackages>()
// .StartsAt(DateTime.Today.AddHours(27)
// )
);
//.AddApiServer();
//.AddApiServer();
})
.AddSingleton<EmailService>()
@@ -101,10 +104,10 @@ namespace PartSource.Automation
})
.ConfigureLogging((builder, logging) =>
{
//logging.AddEventLog();
logging.AddEventLog();
logging.AddConsole();
// logging.AddProvider(new AutomationLoggerProvider());
// logging.AddProvider(new AutomationLoggerProvider());
});
}
}

View File

@@ -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);
}
}
}

View File

@@ -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();
}

View File

@@ -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"
}
}
}
}