Preparata richiesta pr0ocessing validazione (coda iniziale)

This commit is contained in:
Samuele E. Locatelli
2019-12-30 17:43:49 +01:00
parent 54bc215e67
commit de280c0bd8
4 changed files with 118 additions and 17 deletions
+73 -11
View File
@@ -243,14 +243,84 @@ namespace AppData
KeyValuePair<string, string>[] answ = memLayer.ML.redGetHash(redMsgList);
return answ;
}
/// <summary>
/// resetta la richeista corrente in modo che non ce ne siano altre in coda
/// </summary>
/// <returns></returns>
public static bool resetBatchReq()
{
bool answ = false;
try
{
currBatchReq = "";
answ = true;
}
catch
{ }
return answ;
}
public static string currBatchReqKey
{
get
{
return $"{redOutPath}:CURR";
}
}
/// <summary>
/// Valore della richiesta corrente di elaborazione batch
/// </summary>
public static string currBatchReq
{
get
{
return memLayer.ML.getRSV(currBatchReqKey);
}
set
{
// scrivo su REDIS
memLayer.ML.setRSV(currBatchReqKey, value);
}
}
public static bool sendFirstValidationBatch()
{
bool answ = false;
// verifico se sia vuota la richeista corrente (= chiuso...)
// ora verifico, se ci sono batch in stato 8 (da validare) --> metto in coda!
var tabBatch = DataLayer.man.taBL.getByStatus(8);
bool hasValReq = tabBatch.Count > 0;
if (hasValReq)
{
// invia a redis una richiesta...
ComLib.sendMaterials();
// recupero PRIMO batchID da validare
int nextBatchId = 0;
try
{
nextBatchId = tabBatch[0].BatchID;
}
catch
{ }
if (nextBatchId > 0)
{
// richiedo!
ComLib.sendBatchReq(nextBatchId, "Estimation", 1);
// registro su DB nesting iniziato... QUANDO MI RISPONDE dovrò verificare che era un abtch x VALIDAZIONE
DataLayer.man.taBL.updateStatus(nextBatchId, (int)BatchStatus.EstimationRequested, "", 0);
answ = true;
}
}
// resituisco
return answ;
}
/// <summary>
/// Invia una richiesta di esecuzione di Nesting x un Batch
/// </summary>
/// <param name="BatchID">Batch di cui si chiede processing</param>
/// <param name="note">note opzionali</param>
/// <param name="pType">Tipo processo: 1 = stima, 2 = nesting</param>
/// <returns></returns>
public static bool sendBatchReq(int BatchID, string note)
public static bool sendBatchReq(int BatchID, string note, int pType)
{
bool answ = false;
// per prima cosa mi serve una "nuova busta" per inviare i messaggi
@@ -261,7 +331,6 @@ namespace AppData
// in base allo stato del BATCH corrente determino il tempo e le opzioni da inviare...
var batch = DataLayer.man.taBL.getByKey(BatchID);
int mTime = 1;
int pType = 1;
if (batch[0].STATUS < (int)BatchStatus.EstimationDone)
{
mTime = memLayer.ML.cdvi("estimMaxTime");
@@ -269,11 +338,8 @@ namespace AppData
else
{
mTime = memLayer.ML.cdvi("nestMaxTime");
pType = 2;
}
// init oggetti x fare cicli...
Order currOrder = null;
Kit currentKit = null;
@@ -352,9 +418,7 @@ namespace AppData
memLayer.ML.setRSV(redKey, redVal);
// invio notifica che c'è una busta da processare
redKey = $"{redOutPath}:CURR";
// scrivo su REDIS
memLayer.ML.setRSV(redKey, nextEnv);
memLayer.ML.setRSV(currBatchReqKey, nextEnv);
answ = true;
}
catch (Exception exc)
@@ -468,9 +532,7 @@ namespace AppData
memLayer.ML.setRSV(redKey, redVal);
// invio notifica che c'è una busta da processare
redKey = $"{redOutPath}:CURR";
// scrivo su REDIS
memLayer.ML.setRSV(redKey, nextEnv);
memLayer.ML.setRSV(currBatchReqKey, nextEnv);
answ = true;
}
catch (Exception exc)
+41 -4
View File
@@ -21,9 +21,10 @@ namespace NKC_WF.Controllers
{
batchRequest answ = new batchRequest();
// in primis: controllo su redis SE HO una richiista CURRENT di processing...
string redKey = $"{ComLib.redOutPath}:CURR";
string redVal = memLayer.ML.getRSV(redKey);
string envNum = redVal;
#if false
string redKey = $"{ComLib.currBatchReqKey}";
string redVal = memLayer.ML.getRSV(redKey);
string envNum = redVal;
// se c'è carico "la busta" come ID
if (!string.IsNullOrEmpty(redVal))
{
@@ -41,6 +42,27 @@ namespace NKC_WF.Controllers
catch
{ }
}
#endif
string redKey = "";
string redVal = "";
string envNum = ComLib.currBatchReq;
// se c'è carico "la busta" come ID
if (!string.IsNullOrEmpty(envNum))
{
// cerco in REDIS se ci sia l'item richiesto
redKey = $"{ComLib.redOutPath}:{envNum}";
// leggo da redis la stringa...
redVal = memLayer.ML.getRSV(redKey);
// PROVO a deserializzare...
try
{
answ = JsonConvert.DeserializeObject<batchRequest>(redVal);
// aggiungo LA SUA ENV NUM!!!!
answ.EnvNum = envNum;
}
catch
{ }
}
return answ;
}
@@ -118,7 +140,7 @@ namespace NKC_WF.Controllers
* IN BASE al tipo di risposta saprò se
* - è BatchReq / OfflineOrder
* - è stima iniziale o dettaglio (x batch)
* ...
* - si tratta di una stima di validazione o meno...
*
*************************************************/
if (batchProcAnsw.OrderType == oType.BatchRequest)
@@ -228,9 +250,24 @@ namespace NKC_WF.Controllers
{
answ = "NO";
}
// se tutto OK --> tolgo ultimo batch
if (answ == "OK")
{
// invio notifica che c'è una busta da processare
bool resetOk = ComLib.resetBatchReq();
// se tutto ok e ci sono da validare parts --> procedo!
if (resetOk)
{
bool nextValidSent = ComLib.sendFirstValidationBatch();
}
}
// restituisco risposta
return answ;
}
#if false
// POST: api/BatchProc
@@ -80,7 +80,7 @@ namespace NKC_WF.WebUserControls
{
// invia a redis una richiesta...
ComLib.sendMaterials();
ComLib.sendBatchReq(BatchId, "Estimation");
ComLib.sendBatchReq(BatchId, "Estimation", 1);
// registro su DB nesting iniziato...
DataLayer.man.taBL.updateStatus(BatchId, (int)BatchStatus.EstimationRequested, "", 0);
@@ -99,7 +99,7 @@ namespace NKC_WF.WebUserControls
{
// invia a redis a a richiesta...
ComLib.sendMaterials();
ComLib.sendBatchReq(BatchId, "Nesting");
ComLib.sendBatchReq(BatchId, "Nesting", 2);
// registro su DB nesting iniziato...
DataLayer.man.taBL.updateStatus(BatchId, (int)BatchStatus.NestRequested, "", -1);
@@ -202,6 +202,8 @@ namespace NKC_WF.WebUserControls
try
{
DataLayer.man.taBL.createPartValBatch(memLayer.ML.CRS("cadBaseBath"));
// eventualmente mando primo batch da validare...
bool newValidSent = ComLib.sendFirstValidationBatch();
}
catch
{ }