10cd2986cf
Add nlog, PiscalQueueManager modified: Core.Tests/Remote/PiscalSshClientTests.cs modified: Core/DAL/DataService.cs modified: Core/Remote/IPiscalClient.cs modified: Core/Remote/PiscalSshClient.cs new file: Web/Attributes/ActionLogAttribute.cs modified: Web/Controllers/ControllerBase.cs modified: Web/Controllers/LeafInputController.cs modified: Web/Controllers/LeafOutputController.cs new file: Web/NLog.config new file: Web/NLog.xsd new file: Web/Services/PiscalQueueManager.cs modified: Web/Services/PiscalService.cs modified: Web/Startup.cs modified: Web/Web.csproj modified: Web/packages.config Ignore logs Organize piscal queue manager modified: Core/Entities/LeafInputFile.cs modified: Web/Controllers/LeafInputController.cs renamed: Web/Startup.cs -> Web/HangfireStartup.cs modified: Web/Services/PiscalQueueManager.cs modified: Web/Web.csproj cleanup usings in leafinputcontroller
78 lines
2.3 KiB
C#
78 lines
2.3 KiB
C#
using System;
|
|
using System.Linq;
|
|
using LeafWeb.Core.DAL;
|
|
using LeafWeb.Core.Entities;
|
|
using LeafWeb.Core.Remote;
|
|
using NLog;
|
|
|
|
namespace LeafWeb.Web.Services
|
|
{
|
|
public class PiscalQueueManager : IDisposable
|
|
{
|
|
private readonly DataService _dataService;
|
|
private readonly PiscalService _piscalService;
|
|
|
|
public PiscalQueueManager(DataService dataService, PiscalService piscalService)
|
|
{
|
|
_dataService = dataService;
|
|
_piscalService = piscalService;
|
|
}
|
|
|
|
public PiscalQueueManager() : this(new DataService(), new PiscalService()) {}
|
|
|
|
public void ProcessQueue()
|
|
{
|
|
var logger = LogManager.GetCurrentClassLogger();
|
|
|
|
var runningLeafInputFiles = _dataService.GetLeafInputFiles(LeafInputStatusType.Running).ToList();
|
|
foreach (var file in runningLeafInputFiles)
|
|
{
|
|
var status = _piscalService.GetLeafInputFileStatus(file);
|
|
switch (status)
|
|
{
|
|
case PiscalStatus.Running:
|
|
logger.Debug("LeafInputFile: {0}, {1}", file.Id, status);
|
|
// continue running
|
|
break;
|
|
case PiscalStatus.Success:
|
|
logger.Info("LeafInputFile: {0}, {1}", file.Id, status);
|
|
// collect the leaf output
|
|
var leafOutputFiles = _piscalService.RetrieveLeafOutputFile(file).ToList();
|
|
foreach (var outputFile in leafOutputFiles)
|
|
{
|
|
_dataService.AddLeafOutputFile(outputFile);
|
|
}
|
|
logger.Info("LeafInputFile: {0}, output files: {1}", file.Id, string.Join(", ", leafOutputFiles.Select(o => o.Filename)));
|
|
_dataService.SetLeafInputFileStatus(file, LeafInputStatusType.Complete);
|
|
break;
|
|
case PiscalStatus.Error:
|
|
logger.Error("LeafInputFile: {0}", file.Id);
|
|
_dataService.SetLeafInputFileStatus(file, LeafInputStatusType.Error);
|
|
break;
|
|
}
|
|
}
|
|
|
|
runningLeafInputFiles = _dataService.GetLeafInputFiles(LeafInputStatusType.Running).ToList();
|
|
if (!runningLeafInputFiles.Any())
|
|
{
|
|
var queuedFile =
|
|
_dataService
|
|
.GetLeafInputFiles(LeafInputStatusType.Queued)
|
|
.OrderBy(l => l.Id)
|
|
.FirstOrDefault();
|
|
|
|
if (queuedFile != null)
|
|
{
|
|
logger.Info("LeafInputFile: {0}, Start", queuedFile.Id);
|
|
_piscalService.RunLeafInputFile(queuedFile);
|
|
_dataService.SetLeafInputFileStatus(queuedFile, LeafInputStatusType.Running);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_dataService.Dispose();
|
|
}
|
|
}
|
|
} |