ZTMON ;SEA/RDS-TaskMan: Option, ZTMON, Part 1 (Main Loop) ;3/21/07 14:36
;;8.0;KERNEL;**118,127,136,355,446**;Jul 10, 1995;Build 35
;
ENV ;Main Entry Point For Taskman Status Monitor
D EN(1) ;Long mode
Q
EN(MODE) ;
D HOME^%ZIS N %,%H,X,Y,Z,ZT,ZT1,ZT2,ZT3,ZT4,ZTC,ZTCO,ZTD,ZTENV,ZTH,ZTR,ZTUCI,ZTX,ZTY
S U="^" X ^%ZOSF("UCI") S ZTUCI=Y W @IOF
MON D RUN,STATUS,SCHQ
;Continued in ZTMON1
G ^ZTMON1
;
EN2 ;A shorter monitor
D EN(0)
Q
;
RUN ;Evaluate RUN-Node
W @IOF,!!,"Checking Taskman."
S ZTH=$H,ZTR=$G(^%ZTSCH("RUN"))
I ZTR]"" S ZTD=$$DIFF^%ZTM(ZTH,ZTR,0)
S ZTY=$S(ZTR="":0,ZTD>20:0,1:1)
W ?20,"Current $H=",ZTH," (",$$HTE^%ZTLOAD7(ZTH),")"
W !,?22,"RUN NODE=",$S(ZTR]"":ZTR,1:"<Undefined>") I ZTR]"" W " (",$$HTE^%ZTLOAD7(ZTR),")"
W !,"Taskman is ",$S(ZTY:"current.",ZTR]"":"late by "_(ZTD-15)_" seconds."_$C(7),1:"")
W:$D(^%ZTSCH("STOP")) " shutting down" W:'$D(^%ZTSCH("STATUS")) " not running."_$C(7) W "."
Q
;
STATUS ;Evaluate Status List
K X,ZTC S ZT="",ZTH=$$H3^%ZTM($H),ZT2=""
;Tell sub-managers by setting ^%ZTSCH("LOADA",%ZTPAIR)=run^value^time^$J
M ZTC("S")=^%ZTSCH("STATUS"),ZTC("L")=^%ZTSCH("LOADA")
F S ZT=$O(ZTC("S",ZT)) Q:ZT="" S X=ZTC("S",ZT) I $L($P(X,U,3)) S ZTC("D",$P(X,U,3),ZT)=ZT
W !,"Checking the Status List:",!," Node",?14,"weight status",?34,"time",?44," $J"
S ZT=""
F S ZT=$O(ZTC("D",ZT)),ZT1="" Q:ZT="" F S ZT1=$O(ZTC("D",ZT,ZT1)) Q:ZT1="" D
. S %=ZTC("S",ZT1),ZT2=1
. W !?1,ZT W ?15,$S($D(ZTC("L",ZT)):$J($P(ZTC("L",ZT),U,2),3),1:""),?22,$P(%,U,2),?31,$$STIME($P(%,U)) W ?44,ZT1,?54,$P(%,U,4)
. Q
I 'ZT2 W !?5,"The Status List is ",$S(ZTY:"temporarily ",1:""),"empty."
Q
;
SCHQ ;Evaluate Schedule List
N X,ZTL
W !!,"Checking the Schedule List:"
S ZT1=0,ZTCO=0,ZTC=0,ZTH=$$H3^%ZTM($H)
S X=$O(^%ZTSCH(0)),ZTL=$$DIFF(ZTH,X,1)
F S ZT1=$O(^%ZTSCH(ZT1)) Q:'ZT1 D
. F ZT2=0:0 S ZT2=$O(^%ZTSCH(ZT1,ZT2)) Q:ZT2="" S ZTC=ZTC+1 I $$DIFF(ZTH,ZT1,1)>0 S ZTCO=ZTCO+1
W !?5,"Taskman has ",$S('ZTC:"no",1:ZTC)," task",$S(ZTC'=1:"s",1:"")," scheduled."
I ZTC=1 W !?5,"It is ",$S('ZTCO:"not ",1:""),"overdue."
I ZTC>1 W !?5,$S('ZTCO:"None",ZTCO=ZTC&(ZTCO=2):"Both",ZTCO=ZTC:"All",1:ZTCO)," of them ",$S(ZTCO=1:"is",1:"are")," overdue." W:ZTCO>10 *7
I ZTC>0,ZTL>0 W " First task is ",ZTL," seconds late."
Q
;
DIFF(N,O,T) ;Diff in sec.
Q:$G(T) N-O ;For new seconds times
Q N-O*86400-$P(O,",",2)+$P(N,",",2)
;
STIME(%H) ;Status time
I +$H=+%H Q "T@"_$P($$HTE^%ZTLOAD7(%H),"@",2)
Q "T-"_($H-%H)_"@"_$P($$HTE^%ZTLOAD7(%H),"@",2)
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HZTMON 2563 printed Nov 22, 2024@17:26:26 Page 2
ZTMON ;SEA/RDS-TaskMan: Option, ZTMON, Part 1 (Main Loop) ;3/21/07 14:36
+1 ;;8.0;KERNEL;**118,127,136,355,446**;Jul 10, 1995;Build 35
+2 ;
ENV ;Main Entry Point For Taskman Status Monitor
+1 ;Long mode
DO EN(1)
+2 QUIT
EN(MODE) ;
+1 DO HOME^%ZIS
NEW %,%H,X,Y,Z,ZT,ZT1,ZT2,ZT3,ZT4,ZTC,ZTCO,ZTD,ZTENV,ZTH,ZTR,ZTUCI,ZTX,ZTY
+2 SET U="^"
XECUTE ^%ZOSF("UCI")
SET ZTUCI=Y
WRITE @IOF
MON DO RUN
DO STATUS
DO SCHQ
+1 ;Continued in ZTMON1
+2 GOTO ^ZTMON1
+3 ;
EN2 ;A shorter monitor
+1 DO EN(0)
+2 QUIT
+3 ;
RUN ;Evaluate RUN-Node
+1 WRITE @IOF,!!,"Checking Taskman."
+2 SET ZTH=$HOROLOG
SET ZTR=$GET(^%ZTSCH("RUN"))
+3 IF ZTR]""
SET ZTD=$$DIFF^%ZTM(ZTH,ZTR,0)
+4 SET ZTY=$SELECT(ZTR="":0,ZTD>20:0,1:1)
+5 WRITE ?20,"Current $H=",ZTH," (",$$HTE^%ZTLOAD7(ZTH),")"
+6 WRITE !,?22,"RUN NODE=",$SELECT(ZTR]"":ZTR,1:"<Undefined>")
IF ZTR]""
WRITE " (",$$HTE^%ZTLOAD7(ZTR),")"
+7 WRITE !,"Taskman is ",$SELECT(ZTY:"current.",ZTR]"":"late by "_(ZTD-15)_" seconds."_$CHAR(7),1:"")
+8 if $DATA(^%ZTSCH("STOP"))
WRITE " shutting down"
if '$DATA(^%ZTSCH("STATUS"))
WRITE " not running."_$CHAR(7)
WRITE "."
+9 QUIT
+10 ;
STATUS ;Evaluate Status List
+1 KILL X,ZTC
SET ZT=""
SET ZTH=$$H3^%ZTM($HOROLOG)
SET ZT2=""
+2 ;Tell sub-managers by setting ^%ZTSCH("LOADA",%ZTPAIR)=run^value^time^$J
+3 MERGE ZTC("S")=^%ZTSCH("STATUS"),ZTC("L")=^%ZTSCH("LOADA")
+4 FOR
SET ZT=$ORDER(ZTC("S",ZT))
if ZT=""
QUIT
SET X=ZTC("S",ZT)
IF $LENGTH($PIECE(X,U,3))
SET ZTC("D",$PIECE(X,U,3),ZT)=ZT
+5 WRITE !,"Checking the Status List:",!," Node",?14,"weight status",?34,"time",?44," $J"
+6 SET ZT=""
+7 FOR
SET ZT=$ORDER(ZTC("D",ZT))
SET ZT1=""
if ZT=""
QUIT
FOR
SET ZT1=$ORDER(ZTC("D",ZT,ZT1))
if ZT1=""
QUIT
Begin DoDot:1
+8 SET %=ZTC("S",ZT1)
SET ZT2=1
+9 WRITE !?1,ZT
WRITE ?15,$SELECT($DATA(ZTC("L",ZT)):$JUSTIFY($PIECE(ZTC("L",ZT),U,2),3),1:""),?22,$PIECE(%,U,2),?31,$$STIME($PIECE(%,U))
WRITE ?44,ZT1,?54,$PIECE(%,U,4)
+10 QUIT
End DoDot:1
+11 IF 'ZT2
WRITE !?5,"The Status List is ",$SELECT(ZTY:"temporarily ",1:""),"empty."
+12 QUIT
+13 ;
SCHQ ;Evaluate Schedule List
+1 NEW X,ZTL
+2 WRITE !!,"Checking the Schedule List:"
+3 SET ZT1=0
SET ZTCO=0
SET ZTC=0
SET ZTH=$$H3^%ZTM($HOROLOG)
+4 SET X=$ORDER(^%ZTSCH(0))
SET ZTL=$$DIFF(ZTH,X,1)
+5 FOR
SET ZT1=$ORDER(^%ZTSCH(ZT1))
if 'ZT1
QUIT
Begin DoDot:1
+6 FOR ZT2=0:0
SET ZT2=$ORDER(^%ZTSCH(ZT1,ZT2))
if ZT2=""
QUIT
SET ZTC=ZTC+1
IF $$DIFF(ZTH,ZT1,1)>0
SET ZTCO=ZTCO+1
End DoDot:1
+7 WRITE !?5,"Taskman has ",$SELECT('ZTC:"no",1:ZTC)," task",$SELECT(ZTC'=1:"s",1:"")," scheduled."
+8 IF ZTC=1
WRITE !?5,"It is ",$SELECT('ZTCO:"not ",1:""),"overdue."
+9 IF ZTC>1
WRITE !?5,$SELECT('ZTCO:"None",ZTCO=ZTC&(ZTCO=2):"Both",ZTCO=ZTC:"All",1:ZTCO)," of them ",$SELECT(ZTCO=1:"is",1:"are")," overdue."
if ZTCO>10
WRITE *7
+10 IF ZTC>0
IF ZTL>0
WRITE " First task is ",ZTL," seconds late."
+11 QUIT
+12 ;
DIFF(N,O,T) ;Diff in sec.
+1 ;For new seconds times
if $GET(T)
QUIT N-O
+2 QUIT N-O*86400-$PIECE(O,",",2)+$PIECE(N,",",2)
+3 ;
STIME(%H) ;Status time
+1 IF +$HOROLOG=+%H
QUIT "T@"_$PIECE($$HTE^%ZTLOAD7(%H),"@",2)
+2 QUIT "T-"_($HOROLOG-%H)_"@"_$PIECE($$HTE^%ZTLOAD7(%H),"@",2)