Added JSON body and response logging to CreateNewOrder service. Modified how reactor log comments are added for ABORT_ALARM NICA orders. Modified ABORT_ALARM solution to not trigger on WAITING_FOR_MAINTENANCE_UNSCHEDULED

This commit is contained in:
Infineon\StieberD
2025-08-12 16:24:12 -07:00
parent 1f2b73797b
commit f4f63c28e3
2 changed files with 55 additions and 17 deletions

View File

@ -425,7 +425,7 @@ Service CreateNewOrder(EntityType=ENTITY_TYPES, EntityID, OrderType=ORDER_TYPES,
SRP_JSON(objJson, 'SetValue', 'reactorNumber', ReactNo) SRP_JSON(objJson, 'SetValue', 'reactorNumber', ReactNo)
NewChecklistInstIds = Xlate('NICA_CHECKLISTS', NewSortedChecklistIds, 'NICA_BASE_INSTRUCTION_ID', 'X') NewChecklistInstIds = Xlate('NICA_CHECKLISTS', NewSortedChecklistIds, 'NICA_BASE_INSTRUCTION_ID', 'X')
SRP_JSON(objJson, 'SetValueArray', 'baseInstructionIds', NewChecklistInstIds, @VM) SRP_JSON(objJson, 'SetValueArray', 'baseInstructionIds', NewChecklistInstIds, @VM)
Body = SRP_JSON(objJson, 'Stringify', 'Styled') Body = SRP_JSON(objJson, 'Stringify', 'Fast')
Convert @FM to '' in Body Convert @FM to '' in Body
SRP_JSON(objJson, 'Release') SRP_JSON(objJson, 'Release')
end else end else
@ -443,6 +443,7 @@ Service CreateNewOrder(EntityType=ENTITY_TYPES, EntityID, OrderType=ORDER_TYPES,
IsSuccessful = False$ IsSuccessful = False$
If ErrorMsg EQ '' then If ErrorMsg EQ '' then
AttemptNo = 0
Retries = 3 Retries = 3
BackoffSeconds = 1 BackoffSeconds = 1
OrderId = '' OrderId = ''
@ -458,7 +459,32 @@ Service CreateNewOrder(EntityType=ENTITY_TYPES, EntityID, OrderType=ORDER_TYPES,
end else end else
Headers = 'Accept':@VM:'*/*' Headers = 'Accept':@VM:'*/*'
end end
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
LogData<2> = Machine
AttemptNo += 1
LogData<3> = 'Attempt number ':AttemptNo:' to send HTTP POST request to ':NicaURL
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
// Write directly to the log file to avoid mangling the JSON
OSRead LogBytes from LogPath:'\':LogFileName then
LogBytes := CRLF$:Body
OSWrite LogBytes to LogPath:'\':LogFileName
end
HttpResponseJson = Httpclient_Services('SendHTTPRequest', 'POST', NicaURL, Headers, Body, '', '', False$, False$, '', IgnoreCertErrors) HttpResponseJson = Httpclient_Services('SendHTTPRequest', 'POST', NicaURL, Headers, Body, '', '', False$, False$, '', IgnoreCertErrors)
LogData<1> = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS') ; // Logging DTM
LogData<2> = Machine
LogData<3> = 'Attempt number ':AttemptNo:' HttpResponse from ':NicaURL:':'
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
// Write directly to the log file to avoid mangling the JSON
OSRead LogBytes from LogPath:'\':LogFileName then
LogBytes := CRLF$:HttpResponseJson
OSWrite LogBytes to LogPath:'\':LogFileName
end
If HttpResponseJson NE '' then If HttpResponseJson NE '' then
ObjResponseJson = '' ObjResponseJson = ''
If SRP_JSON(ObjResponseJson, 'Parse', HttpResponseJson) EQ '' then If SRP_JSON(ObjResponseJson, 'Parse', HttpResponseJson) EQ '' then

View File

@ -2064,6 +2064,11 @@ Service CreateReactModeChange(UserID, ReactNo, Mode, ModeSubCat, ModeText, Force
Case ( AbortAlarmOrderActive and (SelE10State _EQC 'Productive') ) Case ( AbortAlarmOrderActive and (SelE10State _EQC 'Productive') )
ErrorMsg = "An ABORT/ALARM Checklist is active for this reactor and must be completed or overridden in order to change to a productive state." ErrorMsg = "An ABORT/ALARM Checklist is active for this reactor and must be completed or overridden in order to change to a productive state."
Case ( (Mode _EQC 'WAITING_FOR_MAINTENANCE_UNSCHEDULED') and IndexC(ModeSubCat, 'ABORT/ALARM', 1) )
// Do not create an ABORT/ALARM NICA order yet as maintenance may determine the appropriate ABORT/ALARM sub mode to be different than
// the operator. This avoids creating a NICA order for the wrong flow.
CreateAbortAlarmOrder = False$
Case ( AbortAlarmFromIntrusiveMaintRequired and IndexC(ModeSubCat, 'ABORT/ALARM', 1) and (ModeSubCatFlowId NE '') and (ChecklistIds NE '') ) Case ( AbortAlarmFromIntrusiveMaintRequired and IndexC(ModeSubCat, 'ABORT/ALARM', 1) and (ModeSubCatFlowId NE '') and (ChecklistIds NE '') )
// INTRUSIVE_MAINT FIRST_PRODUCT_RUN_THICK or FIRST_PRODUCT_RUN_HGCV checklist started and // INTRUSIVE_MAINT FIRST_PRODUCT_RUN_THICK or FIRST_PRODUCT_RUN_HGCV checklist started and
// ABORT/ALARM mode entered, so create an ABORT/ALARM order to contain product in reactor. // ABORT/ALARM mode entered, so create an ABORT/ALARM order to contain product in reactor.
@ -2099,7 +2104,11 @@ Service CreateReactModeChange(UserID, ReactNo, Mode, ModeSubCat, ModeText, Force
If CreateAbortAlarmOrder then If CreateAbortAlarmOrder then
Nica_Orders_Services('CreateNewOrder', 'REACTOR', ReactNo, 'ABORT_ALARM', ModeSubCatFlowId, ModeSubCatRespLvl, ChecklistIds, Intrusive) Nica_Orders_Services('CreateNewOrder', 'REACTOR', ReactNo, 'ABORT_ALARM', ModeSubCatFlowId, ModeSubCatRespLvl, ChecklistIds, Intrusive)
If Error_Services('HasError') then
ErrorMsg = Error_Services('GetMessage')
end else
RlComment = 'ABORT/ALARM initiated for flow ':ModeSubCatFlowId:'.' RlComment = 'ABORT/ALARM initiated for flow ':ModeSubCatFlowId:'.'
end
end end
end end
@ -2171,17 +2180,21 @@ Service CreateReactModeChange(UserID, ReactNo, Mode, ModeSubCat, ModeText, Force
EntryId = UserID EntryId = UserID
RLRec = '' RLRec = ''
RLRec<reactor_log_start_date$> = CurDate RLRec<REACTOR_LOG_START_DATE$> = CurDate
RLRec<reactor_log_start_time$> = CurTime RLRec<REACTOR_LOG_START_TIME$> = CurTime
RLRec<reactor_log_reactor$> = ReactNo RLRec<REACTOR_LOG_REACTOR$> = ReactNo
if NewModeCategory EQ 'MAINTENANCE' then If NewModeCategory EQ 'MAINTENANCE' then
RLRec<reactor_log_category$> = 'M' ;* for maintenance RLRec<REACTOR_LOG_CATEGORY$> = 'M' ;* for maintenance
end
RLRec<REACTOR_LOG_ENTRY_ID$> = UserID
RLRec<REACTOR_LOG_ENTRY_DATE$> = CurDate
RLRec<REACTOR_LOG_REACT_UTIL_ID$> = NewRUKey
RLRec<REACTOR_LOG_REACT_PROB_CAT_ID$> = ModeSubCatID
If (RLComment NE '') then
RLRec<REACTOR_LOG_NOTES$> = RLComment
RLRec<REACTOR_LOG_NOTES_DTMS$> = CurDate + (CurTime / SECONDS_IN_DAY$)
RLRec<REACTOR_LOG_NOTES_USERS$> = UserID
end end
RLRec<reactor_log_entry_id$> = UserID
RLRec<reactor_log_entry_date$> = CurDate
RLRec<reactor_log_react_util_id$> = NewRUKey
RLRec<reactor_log_react_prob_cat_id$> = ModeSubCatID
CurrWoNo = Xlate('CONFIG', 'WO_DAILY_SCHED':ReactNo, 'F2', 'X') CurrWoNo = Xlate('CONFIG', 'WO_DAILY_SCHED':ReactNo, 'F2', 'X')
CurrWoNo = CurrWoNo[1, 'F '] CurrWoNo = CurrWoNo[1, 'F ']
If CurrWoNo NE '' then If CurrWoNo NE '' then
@ -2292,7 +2305,6 @@ Service CreateReactModeChange(UserID, ReactNo, Mode, ModeSubCat, ModeText, Force
// Reopen previous react mode // Reopen previous react mode
Database_Services('WriteDataRow', 'REACT_MODE_NG', NGPrevModeKey, PrevModeRec) Database_Services('WriteDataRow', 'REACT_MODE_NG', NGPrevModeKey, PrevModeRec)
end else end else
If RlComment NE '' then Reactor_Log_Services('AddComment', ReactNo, RlComment, UserID)
If SelE10State _EQC 'Productive' then If SelE10State _EQC 'Productive' then
// Reset ABORT/ALARM flag // Reset ABORT/ALARM flag
Open 'REACTOR' to hReactor then Open 'REACTOR' to hReactor then