INHOV1 ;JMB; 24 Aug 95 14:23; Verify Background Processes
;;3.01;BHL IHS Interfaces with GIS;;JUL 01, 2001
;COPYRIGHT 1991-2000 SAIC
;
Q
EN ;Called from INHOP
;New Statements
N DB,BPC,DC,INDEST,DTOUT,GL,S,TAB,X
N INDAT,INEXIT,IN0,INH,INI,INL,INRUN,INITER,INK,INQ,INWARN,INSIG,INT
;
;Initialize report variables
S INITER=0,INEXIT=0,INPAR("START")=$H
;Initialize TABs
S TAB(1)=5,TAB(2)=37,TAB(3)=49,TAB(4)=58,TAB(5)=66,TAB(6)=74
;Load array (INDEST) of queues to check
D DES0^INHUTS1
;Report start time
S INDAT("ST")=$$CDATASC^UTDT(INPAR("START"),1,1)
;
ENRPT ;Repeat entry point
;
;Init scan variables
S INITER=INITER+1,INPAR("QSTART")=$H
;Initialize flags
S INWARN=0,INSIG=0
;
;Set warning flag INWARN to 1 if another user is running this report.
L +^INTHPC("AVERIFY"):1 E S INWARN=1
S BPC=0
F S BPC=$O(INDEST(BPC)) Q:'BPC D VERIFY(BPC)
L:'INWARN -^INTHPC("AVERIFY")
;
;Repeat display for terminals, one time for printers
I 'INTASKED D DIS^INHOV2 S INEXIT=$$QUIT^INHUTS G:INEXIT EXIT
;Check for end of tasked report
I INTASKED,INITER'<INPAR("ITER") D DIS^INHOV2 G EXIT
;
;hang until next recalculation
F X=1:1:INPAR("REPAINT") S:'INTASKED INEXIT=$$QUIT^INHUTS Q:INEXIT H 1
G:INEXIT EXIT
G ENRPT
;
EXIT ;End of program
;Close device
D ^%ZISC
Q
;
VERIFY(INI) ;Verify if all active processes are running
;This is the program main loop. It loops through all active
; background processes.
;Where:
; INI - Process Id
;
N IN0
S IN0=$G(^INRHB("RUN",INI))
D STAT(INI,0,IN0)
D:INPAR("DETAIL") VFY2(INI)
D IN2^INHOV2(INI)
Q
;
STAT(INQ,INK,IN0) ;Build Statistics
; INQ - Background process Id
; INK - Server Id (INK=0 if process is not a server)
; IN0 - Data string from ^INRHB
;OUTPUT:
; Updated INDAT(sub1,sub2,sub3,sub4) array with latest information:
; Where:
; sub1 - Process Id number (ex. 1 for the Output Controller)
; - "CT": Current Time formatted (no sub2,sub3,sub4)
; - "RT": Run Time (no sub2,sub3,sub4)
; - "AR": Avg Run Time per Iteration (no sub2,sub3,sub4)
; sub2 - 0: Not a server; >0: Server Id number
; sub3 - 0: Last Run Time Stats (there is sub4)
; - 1: Last Event Time Stats (there is sub4)
; - "RUN","ITR","MES" (no sub4)
; sub4 - "ETS","ETF","LRU","MIN","MAX" or "AET" (i.e. Stats)
;
; MIN - Minimum elapsed time in sec
; MAX - Maximum elapsed time in sec
; AET - Average elapsed time in sec
; LRU - Last Run Time/Last Event Time in sec
; ITR - Current Background Process iteration
; RUN - Running status
; MES - Message
; ETS - Elapsed time in sec
;
N S,INH,INL,INRUN
;
;Current time formatted
S INDAT("CT")=$$CDATASC^UTDT($$NOW^UTDT,1,1)
;Calculate run time = now-start
S INRUN=$$TDIF^INHUTS(INPAR("START"),$H)
S INDAT("RT")=$$FORMAT^INHUTS(INRUN)
;Calculate average run time per iteration
S INDAT("AR")=$$FORMAT^INHUTS(INRUN\INITER,2)
;
;Is background process running?
S:'INK S=$$VER("^INRHB(""RUN"")",INQ)
S:INK S=$$VER("^INRHB(""RUN"",""SRVR"",INQ)",INK)
S INDAT(INQ,INK,"RUN")=$S(S=1:"",'S:"N",S=2:"N",S=3:"Q")
;Set flag to display message to user on the meaning of "Q"
S:INDAT(INQ,INK,"RUN")="Q" INSIG=1
;
;Message
S:INPAR("DETAIL") INDAT(INQ,INK,"MES")=$P(IN0,U,2)
;
;Number of iterations for each process:
;If the process is deactivated while running this report the count
;will not increase. The count will resume if the process is reactivated.
S:INDAT(INQ,INK,"RUN")="" INDAT(INQ,INK,"ITR")=$G(INDAT(INQ,INK,"ITR"))+1
;
S INH=$H
;Last Run Stats
S INL=$P(IN0,U) D:INL STA1(0,INH,INL)
;Last Event Stats
S INL=$P(IN0,U,3) D:INL&INPAR("DETAIL") STA1(1,INH,INL)
Q
;
STA1(DA,DB,DC) ;Caculates Stats
;INPUT:
; DA - 0 : Last Run Update Stats
; 1 : Last Event Stats
; DB - Current Time in $H format
; DC - Last Update in $H format
;OUTPUT:
; Updated INDAT array
;
;Elapsed Time
S INDAT(INQ,INK,DA,"ELS")=$$TDIF^INHUTS(DC,DB) ;in sec
;
;Total Elapsed
S:INDAT(INQ,INK,"RUN")="" INDAT(INQ,INK,DA,"ELT")=$G(INDAT(INQ,INK,DA,"ELT"))+INDAT(INQ,INK,DA,"ELS")
;
;Last Run Update/Last Message
S INDAT(INQ,INK,DA,"LRU")=DC
;
;Do not compute Stats if process is not running
I INDAT(INQ,INK,"RUN")'="" Q
;
;Average Elapsed Time:
S INDAT(INQ,INK,DA,"AET")=INDAT(INQ,INK,DA,"ELT")/INDAT(INQ,INK,"ITR")
;
;Minimum Elapsed Time
S:INDAT(INQ,INK,DA,"ELS")<$G(INDAT(INQ,INK,DA,"MIN"))!($G(INDAT(INQ,INK,DA,"MIN"))="") INDAT(INQ,INK,DA,"MIN")=INDAT(INQ,INK,DA,"ELS")
;
;Maximum Elapsed Time
S:INDAT(INQ,INK,DA,"ELS")>$G(INDAT(INQ,INK,DA,"MAX"))!($G(INDAT(INQ,INK,DA,"MAX"))="") INDAT(INQ,INK,DA,"MAX")=INDAT(INQ,INK,DA,"ELS")
Q
;
VER(GL,DA) ;Verify if Background Process (or Server) DA is running
;Possible Outputs:
; Acquired Lock D/T Present Value return Meaning
; Y Y 2 Not running
; Y N 0 Not running
; N Y 1 Running
; N N 3 Signaled to quit
L +@GL@(DA):0 I L -@GL@(DA) Q:$D(@GL@(DA)) 2 Q 0
Q:'$D(@GL@(DA)) 3
Q 1
;
VFY2(INI) ;Verify running servers for Background Process INI
;Called from tag VERIFY, which contains the main loop.
; INI - Background process Id
;OUTPUT:
; INDAT - Array with server information
;
N INK
;Initialize servers of process INI
D IN1^INHOV2(INI)
S INK="" F S INK=$O(^INRHB("RUN","SRVR",INI,INK)) Q:'INK D
.S IN0=$G(^INRHB("RUN","SRVR",INI,INK))
.D STAT(INI,INK,IN0)
Q
INHOV1 ;JMB; 24 Aug 95 14:23; Verify Background Processes
+1 ;;3.01;BHL IHS Interfaces with GIS;;JUL 01, 2001
+2 ;COPYRIGHT 1991-2000 SAIC
+3 ;
+4 QUIT
EN ;Called from INHOP
+1 ;New Statements
+2 NEW DB,BPC,DC,INDEST,DTOUT,GL,S,TAB,X
+3 NEW INDAT,INEXIT,IN0,INH,INI,INL,INRUN,INITER,INK,INQ,INWARN,INSIG,INT
+4 ;
+5 ;Initialize report variables
+6 SET INITER=0
SET INEXIT=0
SET INPAR("START")=$HOROLOG
+7 ;Initialize TABs
+8 SET TAB(1)=5
SET TAB(2)=37
SET TAB(3)=49
SET TAB(4)=58
SET TAB(5)=66
SET TAB(6)=74
+9 ;Load array (INDEST) of queues to check
+10 DO DES0^INHUTS1
+11 ;Report start time
+12 SET INDAT("ST")=$$CDATASC^UTDT(INPAR("START"),1,1)
+13 ;
ENRPT ;Repeat entry point
+1 ;
+2 ;Init scan variables
+3 SET INITER=INITER+1
SET INPAR("QSTART")=$HOROLOG
+4 ;Initialize flags
+5 SET INWARN=0
SET INSIG=0
+6 ;
+7 ;Set warning flag INWARN to 1 if another user is running this report.
+8 LOCK +^INTHPC("AVERIFY"):1
IF '$TEST
SET INWARN=1
+9 SET BPC=0
+10 FOR
SET BPC=$ORDER(INDEST(BPC))
IF 'BPC
QUIT
DO VERIFY(BPC)
+11 IF 'INWARN
LOCK -^INTHPC("AVERIFY")
+12 ;
+13 ;Repeat display for terminals, one time for printers
+14 IF 'INTASKED
DO DIS^INHOV2
SET INEXIT=$$QUIT^INHUTS
IF INEXIT
GOTO EXIT
+15 ;Check for end of tasked report
+16 IF INTASKED
IF INITER'<INPAR("ITER")
DO DIS^INHOV2
GOTO EXIT
+17 ;
+18 ;hang until next recalculation
+19 FOR X=1:1:INPAR("REPAINT")
IF 'INTASKED
SET INEXIT=$$QUIT^INHUTS
IF INEXIT
QUIT
HANG 1
+20 IF INEXIT
GOTO EXIT
+21 GOTO ENRPT
+22 ;
EXIT ;End of program
+1 ;Close device
+2 DO ^%ZISC
+3 QUIT
+4 ;
VERIFY(INI) ;Verify if all active processes are running
+1 ;This is the program main loop. It loops through all active
+2 ; background processes.
+3 ;Where:
+4 ; INI - Process Id
+5 ;
+6 NEW IN0
+7 SET IN0=$GET(^INRHB("RUN",INI))
+8 DO STAT(INI,0,IN0)
+9 IF INPAR("DETAIL")
DO VFY2(INI)
+10 DO IN2^INHOV2(INI)
+11 QUIT
+12 ;
STAT(INQ,INK,IN0) ;Build Statistics
+1 ; INQ - Background process Id
+2 ; INK - Server Id (INK=0 if process is not a server)
+3 ; IN0 - Data string from ^INRHB
+4 ;OUTPUT:
+5 ; Updated INDAT(sub1,sub2,sub3,sub4) array with latest information:
+6 ; Where:
+7 ; sub1 - Process Id number (ex. 1 for the Output Controller)
+8 ; - "CT": Current Time formatted (no sub2,sub3,sub4)
+9 ; - "RT": Run Time (no sub2,sub3,sub4)
+10 ; - "AR": Avg Run Time per Iteration (no sub2,sub3,sub4)
+11 ; sub2 - 0: Not a server; >0: Server Id number
+12 ; sub3 - 0: Last Run Time Stats (there is sub4)
+13 ; - 1: Last Event Time Stats (there is sub4)
+14 ; - "RUN","ITR","MES" (no sub4)
+15 ; sub4 - "ETS","ETF","LRU","MIN","MAX" or "AET" (i.e. Stats)
+16 ;
+17 ; MIN - Minimum elapsed time in sec
+18 ; MAX - Maximum elapsed time in sec
+19 ; AET - Average elapsed time in sec
+20 ; LRU - Last Run Time/Last Event Time in sec
+21 ; ITR - Current Background Process iteration
+22 ; RUN - Running status
+23 ; MES - Message
+24 ; ETS - Elapsed time in sec
+25 ;
+26 NEW S,INH,INL,INRUN
+27 ;
+28 ;Current time formatted
+29 SET INDAT("CT")=$$CDATASC^UTDT($$NOW^UTDT,1,1)
+30 ;Calculate run time = now-start
+31 SET INRUN=$$TDIF^INHUTS(INPAR("START"),$HOROLOG)
+32 SET INDAT("RT")=$$FORMAT^INHUTS(INRUN)
+33 ;Calculate average run time per iteration
+34 SET INDAT("AR")=$$FORMAT^INHUTS(INRUN\INITER,2)
+35 ;
+36 ;Is background process running?
+37 IF 'INK
SET S=$$VER("^INRHB(""RUN"")",INQ)
+38 IF INK
SET S=$$VER("^INRHB(""RUN"",""SRVR"",INQ)",INK)
+39 SET INDAT(INQ,INK,"RUN")=$SELECT(S=1:"",'S:"N",S=2:"N",S=3:"Q")
+40 ;Set flag to display message to user on the meaning of "Q"
+41 IF INDAT(INQ,INK,"RUN")="Q"
SET INSIG=1
+42 ;
+43 ;Message
+44 IF INPAR("DETAIL")
SET INDAT(INQ,INK,"MES")=$PIECE(IN0,U,2)
+45 ;
+46 ;Number of iterations for each process:
+47 ;If the process is deactivated while running this report the count
+48 ;will not increase. The count will resume if the process is reactivated.
+49 IF INDAT(INQ,INK,"RUN")=""
SET INDAT(INQ,INK,"ITR")=$GET(INDAT(INQ,INK,"ITR"))+1
+50 ;
+51 SET INH=$HOROLOG
+52 ;Last Run Stats
+53 SET INL=$PIECE(IN0,U)
IF INL
DO STA1(0,INH,INL)
+54 ;Last Event Stats
+55 SET INL=$PIECE(IN0,U,3)
IF INL&INPAR("DETAIL")
DO STA1(1,INH,INL)
+56 QUIT
+57 ;
STA1(DA,DB,DC) ;Caculates Stats
+1 ;INPUT:
+2 ; DA - 0 : Last Run Update Stats
+3 ; 1 : Last Event Stats
+4 ; DB - Current Time in $H format
+5 ; DC - Last Update in $H format
+6 ;OUTPUT:
+7 ; Updated INDAT array
+8 ;
+9 ;Elapsed Time
+10 ;in sec
SET INDAT(INQ,INK,DA,"ELS")=$$TDIF^INHUTS(DC,DB)
+11 ;
+12 ;Total Elapsed
+13 IF INDAT(INQ,INK,"RUN")=""
SET INDAT(INQ,INK,DA,"ELT")=$GET(INDAT(INQ,INK,DA,"ELT"))+INDAT(INQ,INK,DA,"ELS")
+14 ;
+15 ;Last Run Update/Last Message
+16 SET INDAT(INQ,INK,DA,"LRU")=DC
+17 ;
+18 ;Do not compute Stats if process is not running
+19 IF INDAT(INQ,INK,"RUN")'=""
QUIT
+20 ;
+21 ;Average Elapsed Time:
+22 SET INDAT(INQ,INK,DA,"AET")=INDAT(INQ,INK,DA,"ELT")/INDAT(INQ,INK,"ITR")
+23 ;
+24 ;Minimum Elapsed Time
+25 IF INDAT(INQ,INK,DA,"ELS")<$GET(INDAT(INQ,INK,DA,"MIN"))!($GET(INDAT(INQ,INK,DA,"MIN"))="")
SET INDAT(INQ,INK,DA,"MIN")=INDAT(INQ,INK,DA,"ELS")
+26 ;
+27 ;Maximum Elapsed Time
+28 IF INDAT(INQ,INK,DA,"ELS")>$GET(INDAT(INQ,INK,DA,"MAX"))!($GET(INDAT(INQ,INK,DA,"MAX"))="")
SET INDAT(INQ,INK,DA,"MAX")=INDAT(INQ,INK,DA,"ELS")
+29 QUIT
+30 ;
VER(GL,DA) ;Verify if Background Process (or Server) DA is running
+1 ;Possible Outputs:
+2 ; Acquired Lock D/T Present Value return Meaning
+3 ; Y Y 2 Not running
+4 ; Y N 0 Not running
+5 ; N Y 1 Running
+6 ; N N 3 Signaled to quit
+7 LOCK +@GL@(DA):0
IF $TEST
LOCK -@GL@(DA)
IF $DATA(@GL@(DA))
QUIT 2
QUIT 0
+8 IF '$DATA(@GL@(DA))
QUIT 3
+9 QUIT 1
+10 ;
VFY2(INI) ;Verify running servers for Background Process INI
+1 ;Called from tag VERIFY, which contains the main loop.
+2 ; INI - Background process Id
+3 ;OUTPUT:
+4 ; INDAT - Array with server information
+5 ;
+6 NEW INK
+7 ;Initialize servers of process INI
+8 DO IN1^INHOV2(INI)
+9 SET INK=""
FOR
SET INK=$ORDER(^INRHB("RUN","SRVR",INI,INK))
IF 'INK
QUIT
Begin DoDot:1
+10 SET IN0=$GET(^INRHB("RUN","SRVR",INI,INK))
+11 DO STAT(INI,INK,IN0)
End DoDot:1
+12 QUIT