Estensione metodi di lettura QUEUE
This commit is contained in:
@@ -14,7 +14,7 @@ namespace WebDoorCreator.API.Controllers
|
||||
{
|
||||
Log.Info("Starting QueueController");
|
||||
_configuration = configuration;
|
||||
DService = DataService;
|
||||
QDService = DataService;
|
||||
Log.Info("Avviato QueueController");
|
||||
}
|
||||
|
||||
@@ -22,26 +22,64 @@ namespace WebDoorCreator.API.Controllers
|
||||
|
||||
#region Public Methods
|
||||
|
||||
[HttpGet("GetQueueLenght")]
|
||||
public int GetQueueLenght()
|
||||
/// <summary>
|
||||
/// Lunghezza coda in attesa
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("ActPendingLenght")]
|
||||
public async Task<long> ActPendingLenght()
|
||||
{
|
||||
return rndGen.Next(0, 20);
|
||||
long numQueue = await QDService.NumRequestPending();
|
||||
return numQueue;
|
||||
}
|
||||
/// <summary>
|
||||
/// Lunghezza coda in fase di processing
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("ActProcessingLenght")]
|
||||
public async Task<long> ActProcessingLenght()
|
||||
{
|
||||
long numQueue = await QDService.NumRequestProcessing();
|
||||
return numQueue;
|
||||
}
|
||||
|
||||
[HttpGet("GetQueueList")]
|
||||
public IEnumerable<string> GetQueueList()
|
||||
/// <summary>
|
||||
/// Elenco richieste in stato pending
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("ShowPending")]
|
||||
public async Task<Dictionary<string, string>?> ShowPending()
|
||||
{
|
||||
return Enumerable.Range(1, rndGen.Next(5, 20)).Select(index => $"WDC{rndGen.Next(0, 2000):000000}").ToArray();
|
||||
var actQueue = await QDService.RequestPending();
|
||||
return actQueue;// != null && actQueue.Count > 0 ? actQueue : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco richeiste in stato processing
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("ShowProcessing")]
|
||||
public async Task<Dictionary<string, string>> ShowProcessing()
|
||||
{
|
||||
var actQueue = await QDService.RequestProcessing();
|
||||
return actQueue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chiede un numero massimo di items dalla coda NB:
|
||||
/// - verranno tolti dalla coda FIFO richieste
|
||||
/// - verranno messi nella coda FIFO processing
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("TakeProcessingItems")]
|
||||
public async Task<Dictionary<string, string>> TakeProcessingItems(int numItems)
|
||||
{
|
||||
var actQueue = await QDService.RequestPending();
|
||||
return actQueue;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Fields
|
||||
|
||||
protected Random rndGen = new Random();
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static IConfiguration _configuration = null!;
|
||||
@@ -52,7 +90,7 @@ namespace WebDoorCreator.API.Controllers
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private QueueDataService DService { get; set; } = null!;
|
||||
private QueueDataService QDService { get; set; } = null!;
|
||||
|
||||
#endregion Private Properties
|
||||
}
|
||||
|
||||
@@ -128,8 +128,29 @@ namespace WebDoorCreator.API.Data
|
||||
return numReq;
|
||||
}
|
||||
|
||||
/// <summary> Get calculation request pending as Dictionary<string, string> --> (doorId,
|
||||
/// revnumb) </summary>
|
||||
/// <summary>
|
||||
/// Get # of calculation request processing
|
||||
/// </summary>
|
||||
public async Task<long> NumRequestProcessing()
|
||||
{
|
||||
long numReq = 0;
|
||||
string source = "REDIS";
|
||||
Dictionary<string, string> dictResult = new Dictionary<string, string>();
|
||||
// cerco da cache
|
||||
RedisKey currKey = new RedisKey(Constants.CALC_REQ_PROC);
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
numReq = await redisDb.HashLengthAsync(currKey);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"NumRequestProcessing | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return numReq;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Queue request pending
|
||||
/// </summary>
|
||||
/// <returns>Dictionary of DoorId, saveVersNumb</returns>
|
||||
public async Task<Dictionary<string, string>> RequestPending()
|
||||
{
|
||||
string source = "REDIS";
|
||||
@@ -153,6 +174,33 @@ namespace WebDoorCreator.API.Data
|
||||
Log.Debug($"RequestPending | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dictResult;
|
||||
}
|
||||
/// <summary>
|
||||
/// Get Queue request processing
|
||||
/// </summary>
|
||||
/// <returns>Dictionary of DoorId, saveVersNumb</returns>
|
||||
public async Task<Dictionary<string, string>> RequestProcessing()
|
||||
{
|
||||
string source = "REDIS";
|
||||
long numReq = 0;
|
||||
Dictionary<string, string> dictResult = new Dictionary<string, string>();
|
||||
// cerco da cache
|
||||
RedisKey currKey = new RedisKey(Constants.CALC_REQ_PROC);
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
numReq = redisDb.HashLength(currKey);
|
||||
if (numReq > 0)
|
||||
{
|
||||
var rawData = await redisDb.HashGetAllAsync(currKey);
|
||||
foreach (var item in rawData)
|
||||
{
|
||||
dictResult.Add($"{item.Name}", $"{item.Value}");
|
||||
}
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"RequestProcessing | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dictResult;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
|
||||
Reference in New Issue
Block a user