Submit all LeafInputFiles together
This commit is contained in:
@@ -31,25 +31,25 @@ namespace LeafWeb.Web.Services
|
||||
public EmailNotificationService() : this(new DataService())
|
||||
{ }
|
||||
|
||||
public void SendLeafWebError(int leafWebFileId, string errorMessage)
|
||||
public void SendLeafWebError(int leafInputId, string errorMessage)
|
||||
{
|
||||
var file = _dataService.GetLeafInputFile(leafWebFileId);
|
||||
var body = $"Your LeafWeb analysis job, {file.LeafInput.Identifier} (with filename {file.Filename}), encountered the following errors." + Environment.NewLine
|
||||
var leafInput = _dataService.GetLeafInput(leafInputId);
|
||||
var body = $"Your LeafWeb analysis job, {leafInput.Identifier}, encountered the following errors." + Environment.NewLine
|
||||
+ "You will need to correct your input and resubmit." + Environment.NewLine + Environment.NewLine
|
||||
+ errorMessage;
|
||||
var message = new MailMessage(_emaialFromAddress, file.LeafInput.Email, "LeafWeb processing error", body);
|
||||
var message = new MailMessage(_emaialFromAddress, leafInput.Email, "LeafWeb processing error", body);
|
||||
SendMessage(message);
|
||||
}
|
||||
|
||||
public void SendLeafWebSuccess(int leafWebFileId)
|
||||
public void SendLeafWebSuccess(int leafInputId)
|
||||
{
|
||||
var file = _dataService.GetLeafInputFile(leafWebFileId);
|
||||
var body = $"Your LeafWeb analysis job, {file.LeafInput.Identifier} (with filename {file.Filename}), has completed." + Environment.NewLine;
|
||||
var message = new MailMessage(_emaialFromAddress, file.LeafInput.Email, "LeafWeb results", body);
|
||||
var leafInput = _dataService.GetLeafInput(leafInputId);
|
||||
var body = $"Your LeafWeb analysis job, {leafInput.Identifier}, has completed." + Environment.NewLine;
|
||||
var message = new MailMessage(_emaialFromAddress, leafInput.Email, "LeafWeb results", body);
|
||||
|
||||
var fileStreams =
|
||||
(from outputFile in
|
||||
file.LeafOutputFiles
|
||||
leafInput.OutputFiles
|
||||
select Tuple.Create(outputFile, new MemoryStream(outputFile.Contents))).ToList();
|
||||
|
||||
try
|
||||
|
||||
@@ -55,39 +55,39 @@ namespace LeafWeb.Web.Services
|
||||
|
||||
private void ProcessQueue(ILogger logger)
|
||||
{
|
||||
var runningLeafInputFiles = _dataService.GetLeafInputFiles(LeafInputStatusType.Running).ToList();
|
||||
if (runningLeafInputFiles.Any())
|
||||
var runningLeafInputs = _dataService.GetLeafInputs(LeafInputStatusType.Running).ToList();
|
||||
if (runningLeafInputs.Any())
|
||||
return;
|
||||
|
||||
var queuedFile =
|
||||
var pending =
|
||||
_dataService
|
||||
.GetLeafInputFiles(LeafInputStatusType.Queued)
|
||||
.GetLeafInputs(LeafInputStatusType.Pending)
|
||||
.OrderBy(l => l.StatusHistory.Min(sh => sh.DateTime))
|
||||
.FirstOrDefault();
|
||||
|
||||
if (queuedFile == null)
|
||||
if (pending == null)
|
||||
return;
|
||||
|
||||
logger.Info("LeafInputFile: {0}, Start", queuedFile.Id);
|
||||
logger.Info("LeafInputFile: {0}, Start", pending.Id);
|
||||
try
|
||||
{
|
||||
_piscalService.Run(queuedFile);
|
||||
_piscalService.Run(pending);
|
||||
}
|
||||
catch (PiscalClientException ex)
|
||||
{
|
||||
logger.Error("LeafInputFile: {0}, ProcessQueue Exception: {1}", queuedFile.Id, ex.Message);
|
||||
_dataService.SetLeafInputFileStatus(queuedFile, LeafInputStatusType.Error, "Error occurred submitting LeafInput");
|
||||
logger.Error("LeafInputFile: {0}, ProcessQueue Exception: {1}", pending.Id, ex.Message);
|
||||
_dataService.SetLeafInputStatus(pending, LeafInputStatusType.Error, "Error occurred submitting LeafInput");
|
||||
|
||||
// TODO: re-queue
|
||||
//_dataService.SetLeafInputFileStatus(queuedFile, LeafInputStatusType.Queued, "Re-queuing LeafInput");
|
||||
}
|
||||
_dataService.SetLeafInputFileStatus(queuedFile, LeafInputStatusType.Running);
|
||||
_dataService.SetLeafInputStatus(pending, LeafInputStatusType.Running);
|
||||
}
|
||||
|
||||
private void ProcessRunning(ILogger logger)
|
||||
{
|
||||
var runningLeafInputFiles = _dataService.GetLeafInputFiles(LeafInputStatusType.Running).ToList();
|
||||
foreach (var file in runningLeafInputFiles)
|
||||
var running = _dataService.GetLeafInputs(LeafInputStatusType.Running).ToList();
|
||||
foreach (var file in running)
|
||||
{
|
||||
var status = _piscalService.GetStatus(file);
|
||||
try
|
||||
@@ -110,7 +110,7 @@ namespace LeafWeb.Web.Services
|
||||
string.Join(", ", leafOutputFiles.Select(o => o.Filename)));
|
||||
|
||||
// update db
|
||||
_dataService.SetLeafInputFileStatus(file, LeafInputStatusType.Complete);
|
||||
_dataService.SetLeafInputStatus(file, LeafInputStatusType.Complete);
|
||||
|
||||
BackgroundJob.Enqueue(() => _emailService.SendLeafWebSuccess(file.Id));
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace LeafWeb.Web.Services
|
||||
case PiscalStatus.NotStarted:
|
||||
logger.Warn("LeafInputFile: {0}, Not Started, re-queueing", file.Id);
|
||||
// if it's not started, try to requeue the process - unusual state
|
||||
_dataService.SetLeafInputFileStatus(file, LeafInputStatusType.Queued);
|
||||
_dataService.SetLeafInputStatus(file, LeafInputStatusType.Pending);
|
||||
break;
|
||||
|
||||
case PiscalStatus.Error:
|
||||
@@ -131,7 +131,7 @@ namespace LeafWeb.Web.Services
|
||||
var errorMessage = _piscalService.GetErrorMessage(file);
|
||||
logger.Info("LeafInputFile: {0}, Error Message: {1}", file.Id, errorMessage);
|
||||
|
||||
_dataService.SetLeafInputFileStatus(file, LeafInputStatusType.Error, errorMessage);
|
||||
_dataService.SetLeafInputStatus(file, LeafInputStatusType.Error, errorMessage);
|
||||
|
||||
BackgroundJob.Enqueue(() => _emailService.SendLeafWebError(file.Id, errorMessage));
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace LeafWeb.Web.Services
|
||||
catch (PiscalClientException ex)
|
||||
{
|
||||
logger.Error("LeafInputFile: {0}, ProcessRunning Exception: {1}", file.Id, ex.Message);
|
||||
_dataService.SetLeafInputFileStatus(file, LeafInputStatusType.Error, "Error occurred processing LeafInput");
|
||||
_dataService.SetLeafInputStatus(file, LeafInputStatusType.Error, "Error occurred processing LeafInput");
|
||||
|
||||
// TODO: re-queue
|
||||
}
|
||||
|
||||
@@ -18,40 +18,40 @@ namespace LeafWeb.Web.Services
|
||||
{
|
||||
}
|
||||
|
||||
public void Run(LeafInputFile leafInputFile)
|
||||
public void Run(LeafInput leafInput)
|
||||
{
|
||||
var inputFile = new PiscalLeafInputFile(leafInputFile);
|
||||
_piscalClient.RunLeafInputFile(inputFile);
|
||||
var inputFile = new PiscalLeafInput(leafInput);
|
||||
_piscalClient.RunLeafInput(inputFile);
|
||||
}
|
||||
|
||||
public PiscalStatus GetStatus(LeafInputFile leafInputFile)
|
||||
public PiscalStatus GetStatus(LeafInput leafInput)
|
||||
{
|
||||
var inputFile = new PiscalLeafInputFile(leafInputFile);
|
||||
return _piscalClient.GetLeafInputFileStatus(inputFile);
|
||||
var inputFile = new PiscalLeafInput(leafInput);
|
||||
return _piscalClient.GetLeafInputStatus(inputFile);
|
||||
}
|
||||
|
||||
public IEnumerable<LeafOutputFile> RetrieveOutputFiles(LeafInputFile leafInputFile)
|
||||
public IEnumerable<LeafOutputFile> RetrieveOutputFiles(LeafInput leafInput)
|
||||
{
|
||||
var inputFile = new PiscalLeafInputFile(leafInputFile);
|
||||
var piscalLeafOutputFiles = _piscalClient.RetrieveLeafOutput(inputFile);
|
||||
var input = new PiscalLeafInput(leafInput);
|
||||
var piscalLeafOutputFiles = _piscalClient.RetrieveLeafOutput(input);
|
||||
foreach (var file in piscalLeafOutputFiles)
|
||||
{
|
||||
var leafOutputFile = file.GetLeafOutputFile();
|
||||
leafOutputFile.LeafInputFile = leafInputFile;
|
||||
leafOutputFile.LeafInput = leafInput;
|
||||
yield return leafOutputFile;
|
||||
}
|
||||
}
|
||||
|
||||
public string GetErrorMessage(LeafInputFile leafInputFile)
|
||||
public string GetErrorMessage(LeafInput leafInput)
|
||||
{
|
||||
var inputFile = new PiscalLeafInputFile(leafInputFile);
|
||||
var inputFile = new PiscalLeafInput(leafInput);
|
||||
return _piscalClient.GetErrorMessage(inputFile);
|
||||
}
|
||||
|
||||
public void Cleanup(LeafInputFile leafInputFile)
|
||||
public void Cleanup(LeafInput leafInput)
|
||||
{
|
||||
var inputFile = new PiscalLeafInputFile(leafInputFile);
|
||||
_piscalClient.CleanupLeafProcess(inputFile);
|
||||
var input = new PiscalLeafInput(leafInput);
|
||||
_piscalClient.CleanupLeafProcess(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user