OK x comportamento log trace/info/wanr
This commit is contained in:
+18
-23
@@ -1,13 +1,14 @@
|
||||
using GPW.CORE.Api.Data;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NLog;
|
||||
using System.Text;
|
||||
|
||||
namespace GPW.CORE.Api.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class CheckProjController : ControllerBase
|
||||
public class ProjCheckController : ControllerBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
@@ -15,32 +16,30 @@ namespace GPW.CORE.Api.Controllers
|
||||
/// </summary>
|
||||
protected ApiDataService dataService { get; set; }
|
||||
|
||||
private readonly ILogger<CheckProjController> _logger;
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public CheckProjController(ILogger<CheckProjController> logger, ApiDataService DataService)
|
||||
public ProjCheckController(ILogger<ProjCheckController> logger, ApiDataService DataService)
|
||||
{
|
||||
_logger = logger;
|
||||
dataService = DataService;
|
||||
_logger.LogInformation("Avviata classe CheckProj");
|
||||
Log.Info("Avviata classe CheckProj");
|
||||
}
|
||||
|
||||
[HttpGet("TryLock")]
|
||||
[HttpGet("ResAlloc")]
|
||||
public async Task<string> Get()
|
||||
{
|
||||
string answ = "ND";
|
||||
StringBuilder sbLog = new StringBuilder();
|
||||
StringBuilder sbActions = new StringBuilder();
|
||||
sbActions.AppendLine("------------------------------");
|
||||
|
||||
// recupero progetti attivi...
|
||||
Log.Info("----------------------------------------------");
|
||||
var currProj = await dataService.AnagProjActiv();
|
||||
sbLog.AppendLine("-----------------------");
|
||||
sbLog.AppendLine($"Found {currProj.Count} Active Projects");
|
||||
|
||||
Log.Info($"Trovati {currProj.Count} Progetti Attivi");
|
||||
// leggo fasi attive
|
||||
var currFasiAct = await dataService.AnagFasiActiv();
|
||||
sbLog.AppendLine($"Found {currFasiAct.Count} Active Phases");
|
||||
Log.Info($"Trovate {currFasiAct.Count} Fasi Attive");
|
||||
Log.Info("----------------------------------------------");
|
||||
|
||||
sbLog.AppendLine("-----------------------");
|
||||
// ciclo elenco fasi ancestor di ognuno...
|
||||
foreach (var itemProj in currProj)
|
||||
{
|
||||
@@ -48,32 +47,28 @@ namespace GPW.CORE.Api.Controllers
|
||||
var subsetFasi = currFasiAct
|
||||
.Where(x => x.IdxProgetto == itemProj.IdxProgetto && x.IdxFaseAncest == 0)
|
||||
.ToList();
|
||||
sbLog.AppendLine("----------");
|
||||
string projData = $"[{itemProj.IdxProgetto}] {itemProj.ClienteNav.RagSociale} - {itemProj.NomeProj} | Found {subsetFasi.Count} Phases";
|
||||
sbLog.AppendLine(projData);
|
||||
string projData = $"[P.{itemProj.IdxProgetto}] {itemProj.Gruppo} | {itemProj.ClienteNav.RagSociale} | {itemProj.NomeProj} | {subsetFasi.Count} Fasi";
|
||||
Log.Info(projData);
|
||||
|
||||
// ciclo x ogni fase Parent
|
||||
foreach (var parentFase in subsetFasi)
|
||||
{
|
||||
// se ne trovo valuto le ore impiegate...
|
||||
var statoFase = await dataService.CalcOreFase(parentFase.IdxFase);
|
||||
var statoFase = await dataService.CalcOreFase(parentFase.IdxFase, false);
|
||||
|
||||
// se ore usate > (ore budget x %) --> CHIUDO!
|
||||
if (statoFase != null && statoFase.percUsed >= (decimal)statoFase.percOpen)
|
||||
if (statoFase != null && statoFase.totOre >= (statoFase.budgetTime * (decimal)statoFase.percOpen))
|
||||
{
|
||||
// x ora LOG... poi chiudo...
|
||||
string currAction = $"!!! [{parentFase.IdxFase}] Budget exhausted for Phase {parentFase.NomeFase} {statoFase.totOre:N2}h used, {statoFase.percUsed:P1} vs {statoFase.percOpen:P1}";
|
||||
sbLog.AppendLine(currAction);
|
||||
sbActions.AppendLine("----------");
|
||||
string currAction = $"[F.{parentFase.IdxFase}] Budget esaurito in Fase {parentFase.NomeFase} {statoFase.totOre:N2}h consumate, budgt {statoFase.budgetTime:N0} al {statoFase.percOpen:P1}";
|
||||
Log.Warn(currAction);
|
||||
sbActions.AppendLine(projData);
|
||||
sbActions.AppendLine(currAction);
|
||||
sbActions.AppendLine("------------------------------");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// LOG esteso locale
|
||||
_logger.LogInformation(sbLog.ToString());
|
||||
|
||||
// ritorno solo LOG azioni
|
||||
answ = sbActions.ToString();
|
||||
return answ;
|
||||
@@ -40,7 +40,7 @@ namespace GPW.CORE.Api.Data
|
||||
/// <summary>
|
||||
/// TTL da 1 min x cache Redis
|
||||
/// </summary>
|
||||
protected const int shortTTL = 60 * 1;
|
||||
protected const int shortTTL = 60 * 5;
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
@@ -207,7 +207,7 @@ namespace GPW.CORE.Api.Data
|
||||
/// </summary>
|
||||
/// <param name="idxFase"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<CalcOreFasiModel> CalcOreFase(int idxFase)
|
||||
public async Task<CalcOreFasiModel> CalcOreFase(int idxFase, bool doLog)
|
||||
{
|
||||
CalcOreFasiModel? dbResult = new CalcOreFasiModel();
|
||||
string cacheKey = $"{rKeyCalcOreFase}:{idxFase}";
|
||||
@@ -226,7 +226,10 @@ namespace GPW.CORE.Api.Data
|
||||
await setRSV(cacheKey, rawData, shortTTL);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB per CalcOreFase: {ts.TotalMilliseconds} ms");
|
||||
if (doLog)
|
||||
{
|
||||
Log.Trace($"Effettuata lettura da DB per CalcOreFase: {ts.TotalMilliseconds} ms");
|
||||
}
|
||||
}
|
||||
if (dbResult == null)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Version>3.0.2201.2614</Version>
|
||||
<Version>3.0.2201.2615</Version>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
Reference in New Issue
Block a user