WIP
This commit is contained in:
@@ -38,18 +38,18 @@ namespace PartSource.Automation.Jobs
|
||||
{
|
||||
try
|
||||
{
|
||||
FtpFileInfo lastUploadedFile = _ftpService.ListFilesExtended()
|
||||
.Where(f => f.FileType == FtpFileType.File && f.Filename.IndexOf(package) > -1)
|
||||
.OrderByDescending(f => f.Modified)
|
||||
.FirstOrDefault();
|
||||
// FtpFileInfo lastUploadedFile = _ftpService.ListFilesExtended()
|
||||
//.Where(f => f.FileType == FtpFileType.File && f.Filename.IndexOf(package) > -1)
|
||||
//.OrderByDescending(f => f.Modified)
|
||||
//.FirstOrDefault();
|
||||
|
||||
if (lastUploadedFile == null)
|
||||
{
|
||||
_logger.LogInformation($"No {package} file available.");
|
||||
return;
|
||||
}
|
||||
// if (lastUploadedFile == null)
|
||||
// {
|
||||
// _logger.LogInformation($"No {package} file available.");
|
||||
// return;
|
||||
// }
|
||||
|
||||
_ftpService.Download($"{package}.txt");
|
||||
// _ftpService.Download($"{package}.txt");
|
||||
_ssisService.Execute($"{package}.dtsx");
|
||||
|
||||
_logger.LogInformation($"Execution of SSIS package {package} completed successfully.");
|
||||
|
||||
@@ -63,6 +63,8 @@ namespace PartSource.Automation.Jobs
|
||||
Part? existing = await _fitmentContext.Parts.FirstOrDefaultAsync(p => p.Sku == part.Sku);
|
||||
if (existing == null)
|
||||
{
|
||||
_logger.LogInformation("Adding SKU {Sku}: {LineCode} {PartNumber}", part.Sku, part.LineCode, part.PartNumber);
|
||||
|
||||
await _fitmentContext.Parts.AddAsync(part);
|
||||
await _fitmentContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
@@ -32,15 +32,11 @@ namespace PartSource.Automation.Jobs
|
||||
{
|
||||
_logger = logger;
|
||||
_whiSeoService = whiSeoService;
|
||||
|
||||
_seoDataType = SeoDataType.Fitment;
|
||||
|
||||
_ftpConfiguration = configuration.GetSection("ftpServers:WhiConfiguration").Get<FtpConfiguration>();
|
||||
|
||||
_noteDictionary = new ConcurrentDictionary<string, string>();
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2008:Do not create tasks without passing a TaskScheduler", Justification = "<Pending>")]
|
||||
public async Task Run(CancellationToken token, params string[] arguments)
|
||||
{
|
||||
_whiSeoService.TruncateFitmentTables();
|
||||
@@ -56,7 +52,7 @@ namespace PartSource.Automation.Jobs
|
||||
fileGroups.Enqueue(fileGroup);
|
||||
}
|
||||
|
||||
Task[] taskArray = new Task[18];
|
||||
Task[] taskArray = new Task[12];
|
||||
for (int i = 0; i < taskArray.Length; i++)
|
||||
{
|
||||
taskArray[i] = Task.Factory.StartNew(() =>
|
||||
@@ -91,12 +87,12 @@ namespace PartSource.Automation.Jobs
|
||||
_logger.LogInformation($"Created fitment table for part group {tableName}.");
|
||||
|
||||
}
|
||||
});
|
||||
}, token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
|
||||
}
|
||||
|
||||
Task.WaitAll(taskArray);
|
||||
_whiSeoService.SaveNotes(_noteDictionary);
|
||||
|
||||
_whiSeoService.SaveNotes(_noteDictionary);
|
||||
_whiSeoService.CreateFitmentView();
|
||||
}
|
||||
|
||||
|
||||
@@ -121,7 +121,8 @@ namespace PartSource.Automation.Jobs
|
||||
&& int.TryParse(columns[35], out int engineConfigId)
|
||||
&& int.TryParse(columns[36], out int vehicleToEngineConfigId))
|
||||
{
|
||||
if (regionId == 2 && new[] { 5, 6, 7 }.Contains(vehicleTypeId))
|
||||
if (new[] { 5, 6, 7 }.Contains(vehicleTypeId))
|
||||
//if (regionId == 2 && new[] { 5, 6, 7 }.Contains(vehicleTypeId))
|
||||
{
|
||||
dataTable.Rows.Add(new object[] { year, makeId, makeName, modelId, modelName, regionId, regionName, vehicleTypeId, engineConfigId, engineDescription, baseVehicleId, vehicleToEngineConfigId, submodelId, submodelName });
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ using Ratermania.Automation.Interfaces;
|
||||
using Ratermania.Shopify;
|
||||
using Ratermania.Shopify.Resources;
|
||||
using System.Web;
|
||||
using System.IO;
|
||||
|
||||
namespace PartSource.Automation.Jobs
|
||||
{
|
||||
@@ -37,20 +38,24 @@ namespace PartSource.Automation.Jobs
|
||||
|
||||
public async Task Run(CancellationToken token, params string[] arguments)
|
||||
{
|
||||
string logfile = Path.Combine(Path.GetTempPath(), $"missing_fitment_{DateTime.Now:yyyy-MM-dd}.csv");
|
||||
using StreamWriter noFitmentWriter = File.AppendText(logfile);
|
||||
noFitmentWriter.WriteLine("SKU,LineCode,PartNumber");
|
||||
|
||||
IList<string> productTypes = await _fitmentContext.ProductTypes
|
||||
_logger.LogInformation($"Logging products without fitment to {logfile}");
|
||||
|
||||
IList<ProductType> productTypes = await _fitmentContext.ProductTypes
|
||||
.Where(p => p.Active)
|
||||
.Select(p => HttpUtility.UrlEncode(p.Name))
|
||||
.ToListAsync();
|
||||
|
||||
foreach (string productType in productTypes)
|
||||
foreach (ProductType productType in productTypes)
|
||||
{
|
||||
_logger.LogInformation("Processing {productType}", HttpUtility.UrlDecode(productType));
|
||||
_logger.LogInformation("Processing {productType}", productType.Name);
|
||||
|
||||
IEnumerable<Product> products = null;
|
||||
try
|
||||
{
|
||||
products = await _shopifyClient.Products.Get(new Dictionary<string, object> { { "limit", 250 }, { "product_type", productType } });
|
||||
products = await _shopifyClient.Products.Get(new Dictionary<string, object> { { "limit", 250 }, { "product_type", HttpUtility.UrlEncode(productType.Name) } });
|
||||
//products = new List<Product>
|
||||
//{
|
||||
// await _shopifyClient.Products.GetById(7458071052335)
|
||||
@@ -88,6 +93,12 @@ namespace PartSource.Automation.Jobs
|
||||
continue;
|
||||
}
|
||||
|
||||
// Temporarily skip castrol oils
|
||||
if (importData.LineCode == "CST")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Extract Partsource bullet points if present.
|
||||
string bodyHtml = string.IsNullOrEmpty(product.BodyHtml)
|
||||
? string.Empty
|
||||
@@ -99,6 +110,8 @@ namespace PartSource.Automation.Jobs
|
||||
if (!vehicleIdFitment.Any())
|
||||
{
|
||||
Console.WriteLine($"No fitment data for {importData.LineCode} {importData.PartNumber}");
|
||||
noFitmentWriter.WriteLine($"\"{importData.VariantSku}\",\"{importData.LineCode}\",\"{importData.PartNumber}\"");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -181,6 +194,9 @@ namespace PartSource.Automation.Jobs
|
||||
products = await _shopifyClient.Products.GetPrevious();
|
||||
}
|
||||
}
|
||||
|
||||
productType.Active = false;
|
||||
await _fitmentContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,20 +100,20 @@ namespace PartSource.Automation.Jobs
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
count += products.Count();
|
||||
products = await _shopifyClient.Products.GetNext();
|
||||
_logger.LogInformation($"Total updated: {count}");
|
||||
}
|
||||
//try
|
||||
//{
|
||||
// count += products.Count();
|
||||
// products = await _shopifyClient.Products.GetNext();
|
||||
// _logger.LogInformation($"Total updated: {count}");
|
||||
//}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Failed to get the next set of products. Retrying");
|
||||
products = await _shopifyClient.Products.GetPrevious();
|
||||
}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// _logger.LogWarning(ex, "Failed to get the next set of products. Retrying");
|
||||
// products = await _shopifyClient.Products.GetPrevious();
|
||||
//}
|
||||
|
||||
_emailService.Send("Pricing Update Completed", $"The pricing update has completed.");
|
||||
// _emailService.Send("Pricing Update Completed", $"The pricing update has completed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user