Organize Piscal Service items
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
This commit is contained in:
@@ -1,65 +0,0 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using LeafWeb.Core.DAL;
|
||||
using LeafWeb.Core.Entities;
|
||||
using LeafWeb.Core.Remote;
|
||||
|
||||
namespace LeafWeb.Web.Services
|
||||
{
|
||||
public class JobService : IDisposable
|
||||
{
|
||||
protected readonly DataService DataService = new DataService();
|
||||
|
||||
protected IPiscalClient GetPiscalClient()
|
||||
{
|
||||
return new PiscalSshClient(ConfigurationManager.ConnectionStrings["PiscalServer"].ConnectionString);
|
||||
}
|
||||
|
||||
public void ProcessNextLeafInput()
|
||||
{
|
||||
var leafInputFile = DataService.GetNextUnprocessedLeafInputFile();
|
||||
if (leafInputFile == null) // no inputs, quit
|
||||
return;
|
||||
|
||||
var inputFile = new PiscalLeafInputFile(leafInputFile);
|
||||
|
||||
var piscalSshClient = GetPiscalClient();
|
||||
piscalSshClient.SubmitLeafInputFile(inputFile);
|
||||
|
||||
DataService.SetLeafInputFileStatus(leafInputFile, LeafInputStatusType.ProcessStarted);
|
||||
}
|
||||
|
||||
public void UpdateLeafInputStatus()
|
||||
{
|
||||
var leafInputFiles =
|
||||
DataService
|
||||
.GetLeafInputFiles(LeafInputStatusType.ProcessStarted)
|
||||
.Select(f => new PiscalLeafInputFile(f));
|
||||
|
||||
var piscalClient = GetPiscalClient();
|
||||
foreach (var file in leafInputFiles)
|
||||
{
|
||||
var status = piscalClient.GetLeafInputStatus(file);
|
||||
switch (status)
|
||||
{
|
||||
case PiscalStatus.Success:
|
||||
// retrieve LeafOutput
|
||||
var outputFile = piscalClient.RetrieveLeafOutput(file);
|
||||
break;
|
||||
case PiscalStatus.Error:
|
||||
// record error
|
||||
break;
|
||||
case PiscalStatus.Running:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
DataService.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using LeafWeb.Core.Entities;
|
||||
using LeafWeb.Core.Remote;
|
||||
|
||||
namespace LeafWeb.Web.Services
|
||||
{
|
||||
public class PiscalService
|
||||
{
|
||||
private readonly IPiscalClient _piscalClient;
|
||||
|
||||
public PiscalService(IPiscalClient piscalClient)
|
||||
{
|
||||
_piscalClient = piscalClient;
|
||||
}
|
||||
|
||||
public PiscalService() : this(new PiscalSshClient(ConfigurationManager.ConnectionStrings["PiscalServer"].ConnectionString))
|
||||
{
|
||||
}
|
||||
|
||||
public void RunLeafInputFile(LeafInputFile leafInputFile)
|
||||
{
|
||||
var inputFile = new PiscalLeafInputFile(leafInputFile);
|
||||
_piscalClient.RunLeafInputFile(inputFile);
|
||||
}
|
||||
|
||||
public PiscalStatus GetLeafInputFileStatus(LeafInputFile leafInputFile)
|
||||
{
|
||||
var inputFile = new PiscalLeafInputFile(leafInputFile);
|
||||
return _piscalClient.GetLeafInputFileStatus(inputFile);
|
||||
}
|
||||
|
||||
public IEnumerable<LeafOutputFile> RetrieveLeafOutputFile(LeafInputFile leafInputFile)
|
||||
{
|
||||
var inputFile = new PiscalLeafInputFile(leafInputFile);
|
||||
var piscalLeafOutputFiles = _piscalClient.RetrieveLeafOutput(inputFile);
|
||||
foreach (var file in piscalLeafOutputFiles)
|
||||
{
|
||||
var leafOutputFile = file.GetLeafOutputFile();
|
||||
leafOutputFile.LeafInputFile = leafInputFile;
|
||||
yield return leafOutputFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user