- separata verifica connessione Redis

- aggiunta funzione che crea nome univoco per canale di risposta
- aggiunte funzioni asincrone di invio verifica e lettura risultati da Redis
- correzioni in analisi risultati della verifica
This commit is contained in:
Emmanuele Sassi
2025-12-13 12:15:39 +01:00
parent 27e1ddc3f0
commit 4c871f76ef
+103 -28
View File
@@ -89,8 +89,28 @@ local JSON = require( 'JSON')
local QuestionChannel = "EgwVerifyQuestion"
local AnswerChannel = "EgwVerifyAnswer"
local nAnswerChannel_Count = 0
local nAnswerChannel_LastSecond = 0
local nRedisConnectionId = 0
---------------------------------------------------------------------
-- funzione che verifica la connessione a Redis
local function VerifyRedisConnection( sConnectionString)
local bRedisConnect = false
if LUX and LUX.REDISID and LUX.REDISID > 0 then
-- connessione già creata dall'esterno
nRedisConnectionId = LUX.REDISID
elseif nRedisConnectionId == 0 then
-- se nessuna connessione la creo
bRedisConnect, nRedisConnectionId = EgtRedisAsyncConnect( sConnectionString)
if not bRedisConnect then
EgtOutLog( 'Errore! Impossibile connettersi con il server Redis dal Lua!')
end
end
return bRedisConnect
end
---------------------------------------------------------------------
-- funzione che aggiorna CutId e TaskId
local function UpdateCutIdAndTaskId( nPartId)
@@ -207,18 +227,8 @@ end
-- funzione che verifica un pezzo Btl
function BeamWallPipeLib.VerifyBtlPart( nPartId, BarPath, ProjType, sMachineName, GlobState)
-- connessione a Redis
local bRedisConnect = false
if LUX and LUX.REDISID and LUX.REDISID > 0 then
-- connessione già creata dall'esterno
nRedisConnectionId = LUX.REDISID
elseif nRedisConnectionId == 0 then
-- se nessuna connessione la creo
bRedisConnect, nRedisConnectionId = EgtRedisAsyncConnect( 'redis.ufficio:26379, serviceName=devel, DefaultDatabase=6, keepAlive=180, connectTimeout=15000, syncTimeout=15000, asyncTimeout=15000, abortConnect=false, ssl=false, allowAdmin=true')
if not bRedisConnect then
EgtOutLog( 'Errore! Impossibile connettersi con il server Redis dal Lua!')
end
end
-- verifico connessione a Redis
local bRedisConnect = VerifyRedisConnection( 'redis.ufficio:26379, serviceName=devel, DefaultDatabase=6, keepAlive=180, connectTimeout=15000, syncTimeout=15000, asyncTimeout=15000, abortConnect=false, ssl=false, allowAdmin=true')
BarPath = CreateBWEFromPart( nPartId, BarPath)
local CurrAnswerChannel = AnswerChannel .. os.time()
@@ -233,20 +243,7 @@ function BeamWallPipeLib.VerifyBtlPart( nPartId, BarPath, ProjType, sMachineName
OutputChannel = CurrAnswerChannel,
Mode = QUESTION_MODES.VERIFY,
UID = 1}
--Dim BarPath As String = ProjectManagerVM.CurrProd.sProdDirPath & "\Projs\" & CurrPart.nPROJ.ToString("0000")
--Args.Add("BarPath", BarPath)
--Dim nCmdType As CalcIntegration.CmdTypes = CmdTypes.GENERATE
--Select Case CurrPart.nGlobalState
-- Case Core.CalcStates.OK, CalcStates.INFO
-- nCmdType = CalcIntegration.CmdTypes.GENERATE
-- Case Else
-- If CurrPart.nGlobalState = CalcStates.NOTCALCULATED OrElse CurrPart.nFeaturesGlobalState > CalcStates.INFO Then
-- Dim sBTLPartFilePath As String = BarPath & "\" & CurrPart.nPDN.ToString() & ".ori.bwe"
-- If File.Exists(sBTLPartFilePath) Then File.Delete(sBTLPartFilePath)
-- End If
-- nCmdType = CalcIntegration.CmdTypes.CHECKNOSIM
--End Select
--Args.Add("CmdType", nCmdType)
local Question = { nThreadIndex = 0,
nId = 1,
ExecEnvironment = 2,
@@ -281,6 +278,84 @@ function BeamWallPipeLib.VerifyBtlPart( nPartId, BarPath, ProjType, sMachineName
end
end
local function GetAnswerChannelCode()
local nCurrTime = os.time()
if nCurrTime == nAnswerChannel_LastSecond then
nAnswerChannel_Count = nAnswerChannel_Count + 1
return nCurrTime .. nAnswerChannel_Count
else
nAnswerChannel_LastSecond = nCurrTime
nAnswerChannel_Count = 0
return nCurrTime
end
end
function BeamWallPipeLib.AsyncVerifyBtlPartCalc( nPartId, BarPath, ProjType, sMachineName, GlobState)
-- verifico connessione a Redis
local bRedisConnect = VerifyRedisConnection( 'redis.ufficio:26379, serviceName=devel, DefaultDatabase=6, keepAlive=180, connectTimeout=15000, syncTimeout=15000, asyncTimeout=15000, abortConnect=false, ssl=false, allowAdmin=true')
BarPath = CreateBWEFromPart( nPartId, BarPath)
local CurrAnswerChannel = AnswerChannel .. GetAnswerChannelCode()
local Args = { BarId = nPartId,
--ProgramPage = PROJECT_TYPES.PROJ,
BarPath = BarPath,
--ProjType = BWTYPES.BEAM,
MachineName = sMachineName,
--GlobState = CALCSTATES.NOTCALCULATED,
CmdType = CMDTYPES.CHECKNOSIM,
OutputChannel = CurrAnswerChannel,
Mode = QUESTION_MODES.VERIFY,
UID = 1}
local Question = { nThreadIndex = 0,
nId = 1,
ExecEnvironment = 2,
Args = Args}
local JsonQuestion = JSON:encode( Question)
local bOk = EgtRedisAsyncPublish( nRedisConnectionId, QuestionChannel, JsonQuestion)
if bOk then
EgtRedisAsyncSubscribe( nRedisConnectionId, CurrAnswerChannel)
end
return bOk, CurrAnswerChannel
end
function BeamWallPipeLib.AsyncVerifyBtlPartResult( CurrAnswerChannel)
-- verifico connessione a Redis
local bRedisConnect = VerifyRedisConnection( 'redis.ufficio:26379, serviceName=devel, DefaultDatabase=6, keepAlive=180, connectTimeout=15000, syncTimeout=15000, asyncTimeout=15000, abortConnect=false, ssl=false, allowAdmin=true')
local bOk, nCount, Answer = EgtRedisAsyncGetMessage( nRedisConnectionId, CurrAnswerChannel)
if bRedisConnect then
EgtRedisAsyncDisconnect( nRedisConnectionId)
nRedisConnectionId = 0
end
if bOk then
if nCount > 0 then
EgtOutLog('Risposta Redis ricevuta:' .. Answer)
EgtRedisAsyncUnsubscribe( nRedisConnectionId, CurrAnswerChannel)
EgtOutLog( 'EgtRedisAsyncUnsubscribe ' .. nRedisConnectionId .. ' ' .. CurrAnswerChannel)
local JsonAnswer = JSON:decode( Answer)
if JsonAnswer then
AnswerArgs = JsonAnswer['Args']
AnswerArgs.OutputChannel = nil
return true, true, AnswerArgs
else
return true, true
end
else
return true, false
end
else
return false
end
end
---------------------------------------------------------------------
-- funzione che analizza i risultati della verifica
local function AnalyzeResult( RESULT)
@@ -289,11 +364,11 @@ local function AnalyzeResult( RESULT)
for nElementIndex = 1, #RESULT do
local CurrElement = RESULT[nElementIndex]
if CurrElement.sType == 'Part' then
if CurrElement.nErr > 0 then
if tonumber( CurrElement.nErr) > 0 then
bMachiningOk = false
end
elseif CurrElement.sType == 'Feature' then
if not CurrElement.ChosenStrategy or not CurrElement.ChosenStrategy.sStatus or ( CurrElement.ChosenStrategy.sStatus ~= 'Completed' and CurrElement.ChosenStrategy.sStatus ~= 'NotCompleted') then
if not CurrElement.ChosenStrategy or not CurrElement.ChosenStrategy.sStatus or ( CurrElement.ChosenStrategy.sStatus ~= 'Completed' and CurrElement.ChosenStrategy.sStatus ~= 'Not-Completed') then
bMachiningOk = false
end
elseif CurrElement.sType == 'Time' then