Threaded ProcessWhiFitment
This commit is contained in:
@@ -39,6 +39,7 @@ namespace PartSource.Automation.Jobs
|
||||
_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()
|
||||
{
|
||||
_whiSeoService.TruncateFitmentTables();
|
||||
@@ -54,46 +55,46 @@ namespace PartSource.Automation.Jobs
|
||||
fileGroups.Enqueue(fileGroup);
|
||||
}
|
||||
|
||||
while (fileGroups.Count > 0)
|
||||
Task[] taskArray = new Task[8];
|
||||
|
||||
for (int i = 0; i < taskArray.Length; i++)
|
||||
{
|
||||
Parallel.For(0, 2, i =>
|
||||
taskArray[i] = Task.Factory.StartNew(() =>
|
||||
{
|
||||
bool result = fileGroups.TryDequeue(out IGrouping<string, FileInfo> fileGroup);
|
||||
|
||||
if (!result)
|
||||
while (fileGroups.TryDequeue(out IGrouping<string, FileInfo> fileGroup))
|
||||
{
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
foreach (FileInfo fileInfo in fileGroup)
|
||||
{
|
||||
try
|
||||
foreach (FileInfo fileInfo in fileGroup)
|
||||
{
|
||||
string filename = Decompress(fileInfo);
|
||||
string tableName = fileInfo.Name.Substring(0, fileInfo.Name.IndexOf('.'));
|
||||
try
|
||||
{
|
||||
string filename = Decompress(fileInfo);
|
||||
string tableName = fileInfo.Name.Substring(0, fileInfo.Name.IndexOf('.'));
|
||||
|
||||
DataTable dataTable = GetDataTable(filename);
|
||||
DataTable dataTable = GetDataTable(filename);
|
||||
|
||||
_whiSeoService.BulkCopyFitment(dataTable, tableName);
|
||||
_logger.LogInformation($"Copied {fileInfo.Name} to the database.");
|
||||
_whiSeoService.BulkCopyFitment(dataTable, tableName);
|
||||
_logger.LogInformation($"Copied {fileInfo.Name} to the database.");
|
||||
|
||||
File.Delete(filename);
|
||||
File.Delete(filename);
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"Failed to write {fileInfo.Name} to the database - {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"Failed to write {fileInfo.Name} to the database - {ex.Message}", ex);
|
||||
}
|
||||
string fitmentTable = fileGroup.Key.Substring(0, fileGroup.Key.IndexOf('.'));
|
||||
_whiSeoService.CreateFitmentTable(fitmentTable);
|
||||
|
||||
_logger.LogInformation($"Created fitment table for part group {fitmentTable}.");
|
||||
|
||||
}
|
||||
|
||||
string fitmentTable = fileGroup.Key.Substring(0, fileGroup.Key.IndexOf('.'));
|
||||
_whiSeoService.CreateFitmentTable(fitmentTable);
|
||||
|
||||
_logger.LogInformation($"Created fitment table for part group {fitmentTable}.");
|
||||
});
|
||||
}
|
||||
|
||||
Task.WaitAll(taskArray);
|
||||
|
||||
_whiSeoService.CreateFitmentView();
|
||||
|
||||
_whiSeoService.SaveNotes(_noteDictionary);
|
||||
@@ -135,7 +136,7 @@ namespace PartSource.Automation.Jobs
|
||||
}
|
||||
|
||||
string lineCode = Regex.Replace(columns[0], "[^a-zA-Z0-9]", string.Empty).Trim();
|
||||
string partNumber = Regex.Replace(columns[1], "[^a-zA-Z0-9\\-]", string.Empty).Trim();
|
||||
string partNumber = Regex.Replace(columns[1], "[^a-zA-Z0-9]", string.Empty).Trim();
|
||||
string position = columns[7].Trim();
|
||||
|
||||
string noteText = columns[4].Trim();
|
||||
|
||||
Reference in New Issue
Block a user