Add Hangfire
Adjust namespace
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using LeafWeb.Core.Entities;
|
||||
using LeafWeb.Core.Parsers;
|
||||
using LeafWeb.WebCms.App_Start;
|
||||
|
||||
namespace LeafWeb.WebCms.Services.PiscalQueue
|
||||
{
|
||||
public class FinishComplete : PiscalQueueWorker
|
||||
{
|
||||
protected override void DoWorkInternal(LeafInput leafInput)
|
||||
{
|
||||
Logger.DebugFormat("LeafInput: {0}, RetrieveOutputFiles", leafInput.Id);
|
||||
|
||||
var leafOutputFiles = PiscalService.RetrieveOutputFiles(leafInput).ToList();
|
||||
|
||||
Logger.DebugFormat("LeafInput: {0}, RetrieveOutputFiles saving output files", leafInput.Id);
|
||||
|
||||
foreach (var outputFile in leafOutputFiles)
|
||||
{
|
||||
if (leafInput.OutputFiles.All(file => file.Filename != outputFile.Filename))
|
||||
{
|
||||
DataService.AddLeafOutputFile(outputFile);
|
||||
|
||||
// parse cleaned input file data
|
||||
if (outputFile.FileType == LeafOutputFileType.CleanedInput)
|
||||
AddLeafInputData(outputFile, leafInput);
|
||||
}
|
||||
else
|
||||
Logger.WarnFormat("LeafInput: {0}, RetrieveOutputFiles duplicate file name: {1}", leafInput.Id, outputFile.Filename);
|
||||
}
|
||||
|
||||
Logger.InfoFormat("LeafInput: {0}, RetrieveOutputFiles output files: {1}", leafInput.Id,
|
||||
string.Join(", ", leafOutputFiles.Select(o => o.Filename)));
|
||||
|
||||
Logger.DebugFormat("LeafInput: {0}, Set Complete", leafInput.Id);
|
||||
DataService.SetLeafInputStatus(leafInput, LeafInputStatusType.Complete);
|
||||
|
||||
BackgroundJobEnqueueRetry<EmailNotificationService>(email => email.SendLeafWebComplete(leafInput.Id));
|
||||
|
||||
Logger.InfoFormat("LeafInput: {0}, Cleanup", leafInput.Id);
|
||||
PiscalService.Cleanup(leafInput);
|
||||
|
||||
HangfireStartup.TriggerPiscalProcessQueue();
|
||||
}
|
||||
|
||||
private void AddLeafInputData(LeafOutputFile outputFile, LeafInput leafInput)
|
||||
{
|
||||
try
|
||||
{
|
||||
var parser = new LeafInputCsvParser(outputFile.FileContents.Contents);
|
||||
var data = parser.Parse();
|
||||
data.LeafInput = leafInput;
|
||||
data.LeafOutputFile = outputFile;
|
||||
leafInput.LeafInputData.Add(data);
|
||||
DataService.UpdateLeafInput(leafInput);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error($"LeafInput: {leafInput.Id}, while parsing CleanedInput file: {outputFile.Filename}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user