ZTMKU ;SEA/RDS-Taskman: Option, ZTMWAIT/RUN/STOP ;01/05/09 16:07
;;8.0;KERNEL;**118,127,275,355,518**;Jul 10, 1995;Build 8
;Per VHA Directive 2004-038, this routine should not be modified.
N DIR,DTOUT,DUOUT
D TABLE ;Show taskman
S DTIME=$G(DTIME,300),DIR(0)="N^1:4",DIR("A",.1)=""
S DIR("A",1)=" 1. Remove from WAIT state.(RUN)",DIR("A",2)=" 2. Managers Update.",DIR("A",3)=" 3. Put into WAIT state."
S DIR("A",4)=" 4. STOP Taskman."
S DIR("A",99)="",DIR("A")="Select Option" D ^DIR
G RUN:Y=1,UPDATE:Y=2,WAIT:Y=3,STOP:Y=4
Q
;
RUN ;Remove Task Managers From WAIT State
D WS(0,"MGR"),WS(0,"SUB") K ^%ZTSCH("STOP") W !,"TaskMan removed from 'WAIT STATE'.",!
Q
;
UPDATE ;Have Managers Do an parameter Update
K ^%ZTSCH("UPDATE")
W !,"Managers will update parameters.",!
Q
;
WAIT ;Put Task Managers In WAIT State
D WS(1,"MGR") W !,"TaskMan now in 'WAIT STATE'",$C(7)
D QSUB
Q
;
STOP ;Shut Down Task Managers
N ZTX,ND,J
F R !!,"Are you sure you want to stop TaskMan? NO// ",ZTX:$S($D(DTIME)#2:DTIME,1:60) S ZTX=$$UP(ZTX) Q:'$T!("^YES^NO"[ZTX) W:ZTX'["?" $C(7) W !,"Answer YES to shut down all Task Managers on current the volume set."
I "^NO"[ZTX W !,"TaskMan NOT shut down." Q
W !,"Shutting down TaskMan." D GROUP("SMAN(NODE)")
D QSUB,ASKACT
Q
;
SSUB(NODE) ;Stop sub-managers
D SS(1,"SUB",NODE)
Q
SMAN(NODE) ;stop managers
D SS(1,"MGR",NODE)
Q
;
SS(MD,GR,NODE) ;Set/clear STOP nodes.
S GR=$G(GR,"MGR") S:"MGR_SUB_"'[GR GR="MGR"
I MD=1 S ^%ZTSCH("STOP",GR,NODE)=$H D WS(0,GR)
I MD=0 K ^%ZTSCH("STOP",GR,NODE)
Q
;
WS(MD,GR) ;Set/Clear Wait state
S GR=$G(GR,"MGR") S:"MGR_SUB_"'[GR GR="MGR"
I MD=1 S ^%ZTSCH("WAIT",GR)=$H ;set wait state
I MD=0 K ^%ZTSCH("WAIT",GR) ;Clear wait
Q
;
GROUP(CALL) ;Do CALL for each node, use NODE as the parameter
N J,ND,NODE
;Get the Managers
F J=0:0 S J=$O(^%ZTSCH("STATUS",J)) Q:J="" S ND=$G(^(J)),NODE=$P(ND,"^",3) D @CALL
;Get any remote Sub-Managers
S NODE="" F S NODE=$O(^%ZTSCH("SUB",NODE)) Q:NODE="" D @CALL
Q
;
OPT(MD) ;Disable/Enable option prosessing
I MD=1 S ^%ZTSCH("NO-OPTION")=""
I MD=0 K ^%ZTSCH("NO-OPTION")
Q
;
ASKACT ;Ask if active Tasks should be signaled to stop.
N ZTX,ND
F R !!,"Should active jobs be signaled to stop? NO// ",ZTX:$G(DTIME,60) S ZTX=$$UP(ZTX) Q:'$T!("^YES^NO"[ZTX) W:ZTX'["?" $C(7) W !,"Answer YES to set the STOP flag for active tasks.",!,"Tasks need to call $$S^%ZTLOAD to get the signal."
I "^NO"[ZTX W !,"Tasks NOT signaled to shut down." Q
W !!,"Signaling active Tasks to STOP."
D STPACT W !,"Done."
Q
;
STPACT ;Set the STOP flag for all ACTIVE Tasks.
N ZTI,ZT2
S ZTI=0
F S ZTI=$O(^%ZTSCH("TASK",ZTI)) Q:'ZTI S ZT2=$$ASKSTOP^%ZTLOAD(ZTI) W !,"TASK: ",ZTI," Stop status: ",ZT2
Q
;
QSUB N ZTX,ND
F R !!,"Should active submanagers shut down after finishing their current tasks? NO// ",ZTX:$S($D(DTIME)#2:DTIME,1:60) Q:'$T!("^"[ZTX)!("YESyesNOno"[ZTX) W:ZTX'["?" $C(7) W !,"Please answer YES or NO."
D:"YESyes"[ZTX&(ZTX]"") GROUP("SSUB(NODE)") W !,"Okay!",!
Q
;
QUERY ;Query Status Of A Task Manager
Q:$D(%ZTX)[0 Q:%ZTX="" S %ZTY=0
I $D(^%ZTSCH("STATUS",%ZTX))#2 S %ZTY=^%ZTSCH("STATUS",%ZTX)
K %ZTX Q
;
NODES ;Return Task Manager Status Nodes
S %ZTX="" F %ZTY=0:0 S %ZTX=$O(^%ZTSCH("STATUS",%ZTX)) Q:%ZTX="" S %ZTY=%ZTY+1,%ZTY(%ZTY)=%ZTX
K %ZTX Q
;
LIVE ;Return Whether A Task Manager Is Live
Q:$D(%ZTX)[0 Q:%ZTX="" S %ZTY=0,U="^",%ZTX1=$H,%ZTX2=$P(%ZTX,U)
S %ZTX3=%ZTX1-%ZTX2*86400+$P(%ZTX1,",",2)-$P(%ZTX2,",",2)
I %ZTX3'<0 S %ZTY=$S($D(^%ZTSCH("RUN"))[0&(%ZTX'["WAIT"):0,%ZTX3<30:1,%ZTX3<120&(%ZTX["PAUSE"):1,1:0)
K %ZTX,%ZTX1,%ZTX2,%ZTX3 Q
;
TABLE ;Display Task Manager Table
W !,"JOB NUMBER",?15,"STATUS",?25,"DESCRIPTION",?55,"LAST UPDATED",?75,"LIVE"
W !,"----------",?15,"------",?25,"-----------",?55,"------------",?75,"----"
D NODES S %ZTZ=%ZTY,%ZTZ1=0,U="^",%H=$H D YMD^%DTC S DT=X
F %ZTI=1:1:%ZTZ S %ZTX=%ZTY(%ZTI) D QUERY I %ZTY'=0 W !,%ZTY(%ZTI),?15,$P(%ZTY,U,2),?25,$P(%ZTY,U,3),?55 S %ZTT=$P(%ZTY,U) D T S %ZTX=%ZTY D LIVE W ?75,$S(%ZTY:"YES",1:"NO") I %ZTY S %ZTZ1=%ZTZ1+1
W !?6,"Total:",$J(%ZTZ,3),!?6,"Live :",$J(%ZTZ1,3)
K %ZTI,%ZTT,%ZTY,%ZTZ Q
;
CLEAN ;Cleanup Status Node
K ^%ZTSCH("STATUS") W !,"Done!",! Q
PURGE ;Purge the TASK list of running tasks.
N TSK S TSK=0
F S TSK=$O(^%ZTSCH("TASK",TSK)) Q:TSK'>0 I '$D(^%ZTSCH("TASK",TSK,"P")) K ^%ZTSCH("TASK",TSK)
W !,"Done!",! Q
;
ZTM ;Return Number Of Live Task Managers
N %ZTI,%ZTZ,%ZTZ1
D NODES S %ZTZ=%ZTY,%ZTZ1=0 F %ZTI=1:1:%ZTZ S %ZTX=%ZTY(%ZTI) D QUERY I %ZTY'=0 S %ZTX=%ZTY D LIVE I %ZTY S %ZTZ1=%ZTZ1+1
S %ZTY=%ZTZ1 Q
;
UP(X) ;Convert to Uppercase
Q $TR(X,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
;
T ;Print Informal-format Conversion Of $H-format Date ; Input: %ZTT, DT.
S %H=%ZTT D 7^%DTC W $S(DT=X:"TODAY",DT+1=X:"TOMORROW",1:$E(X,4,5)_"/"_$E(X,6,7)_"/"_$E(X,2,3))_" AT " S X=$P(%ZTT,",",2)\60,%H=X\60 W $E(%H+100,2,3)_":"_$E(X#60+100,2,3)
K %,%D,%H,%M,%Y,X Q ; Output: %ZTT, DT.
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HZTMKU 5105 printed Nov 22, 2024@17:26:25 Page 2
ZTMKU ;SEA/RDS-Taskman: Option, ZTMWAIT/RUN/STOP ;01/05/09 16:07
+1 ;;8.0;KERNEL;**118,127,275,355,518**;Jul 10, 1995;Build 8
+2 ;Per VHA Directive 2004-038, this routine should not be modified.
+1 NEW DIR,DTOUT,DUOUT
+2 ;Show taskman
DO TABLE
+3 SET DTIME=$GET(DTIME,300)
SET DIR(0)="N^1:4"
SET DIR("A",.1)=""
+4 SET DIR("A",1)=" 1. Remove from WAIT state.(RUN)"
SET DIR("A",2)=" 2. Managers Update."
SET DIR("A",3)=" 3. Put into WAIT state."
+5 SET DIR("A",4)=" 4. STOP Taskman."
+6 SET DIR("A",99)=""
SET DIR("A")="Select Option"
DO ^DIR
+7 if Y=1
GOTO RUN
if Y=2
GOTO UPDATE
if Y=3
GOTO WAIT
if Y=4
GOTO STOP
+8 QUIT
+9 ;
RUN ;Remove Task Managers From WAIT State
+1 DO WS(0,"MGR")
DO WS(0,"SUB")
KILL ^%ZTSCH("STOP")
WRITE !,"TaskMan removed from 'WAIT STATE'.",!
+2 QUIT
+3 ;
UPDATE ;Have Managers Do an parameter Update
+1 KILL ^%ZTSCH("UPDATE")
+2 WRITE !,"Managers will update parameters.",!
+3 QUIT
+4 ;
WAIT ;Put Task Managers In WAIT State
+1 DO WS(1,"MGR")
WRITE !,"TaskMan now in 'WAIT STATE'",$CHAR(7)
+2 DO QSUB
+3 QUIT
+4 ;
STOP ;Shut Down Task Managers
+1 NEW ZTX,ND,J
+2 FOR
READ !!,"Are you sure you want to stop TaskMan? NO// ",ZTX:$SELECT($DATA(DTIME)#2:DTIME,1:60)
SET ZTX=$$UP(ZTX)
if '$TEST!("^YES^NO"[ZTX)
QUIT
if ZTX'["?"
WRITE $CHAR(7)
WRITE !,"Answer YES to shut down all Task Managers on current the volume set."
+3 IF "^NO"[ZTX
WRITE !,"TaskMan NOT shut down."
QUIT
+4 WRITE !,"Shutting down TaskMan."
DO GROUP("SMAN(NODE)")
+5 DO QSUB
DO ASKACT
+6 QUIT
+7 ;
SSUB(NODE) ;Stop sub-managers
+1 DO SS(1,"SUB",NODE)
+2 QUIT
SMAN(NODE) ;stop managers
+1 DO SS(1,"MGR",NODE)
+2 QUIT
+3 ;
SS(MD,GR,NODE) ;Set/clear STOP nodes.
+1 SET GR=$GET(GR,"MGR")
if "MGR_SUB_"'[GR
SET GR="MGR"
+2 IF MD=1
SET ^%ZTSCH("STOP",GR,NODE)=$HOROLOG
DO WS(0,GR)
+3 IF MD=0
KILL ^%ZTSCH("STOP",GR,NODE)
+4 QUIT
+5 ;
WS(MD,GR) ;Set/Clear Wait state
+1 SET GR=$GET(GR,"MGR")
if "MGR_SUB_"'[GR
SET GR="MGR"
+2 ;set wait state
IF MD=1
SET ^%ZTSCH("WAIT",GR)=$HOROLOG
+3 ;Clear wait
IF MD=0
KILL ^%ZTSCH("WAIT",GR)
+4 QUIT
+5 ;
GROUP(CALL) ;Do CALL for each node, use NODE as the parameter
+1 NEW J,ND,NODE
+2 ;Get the Managers
+3 FOR J=0:0
SET J=$ORDER(^%ZTSCH("STATUS",J))
if J=""
QUIT
SET ND=$GET(^(J))
SET NODE=$PIECE(ND,"^",3)
DO @CALL
+4 ;Get any remote Sub-Managers
+5 SET NODE=""
FOR
SET NODE=$ORDER(^%ZTSCH("SUB",NODE))
if NODE=""
QUIT
DO @CALL
+6 QUIT
+7 ;
OPT(MD) ;Disable/Enable option prosessing
+1 IF MD=1
SET ^%ZTSCH("NO-OPTION")=""
+2 IF MD=0
KILL ^%ZTSCH("NO-OPTION")
+3 QUIT
+4 ;
ASKACT ;Ask if active Tasks should be signaled to stop.
+1 NEW ZTX,ND
+2 FOR
READ !!,"Should active jobs be signaled to stop? NO// ",ZTX:$GET(DTIME,60)
SET ZTX=$$UP(ZTX)
if '$TEST!("^YES^NO"[ZTX)
QUIT
if ZTX'["?"
WRITE $CHAR(7)
WRITE !,"Answer YES to set the STOP flag for active tasks.",!,"Tasks need to call $$S^%ZTLOAD to get the signal."
+3 IF "^NO"[ZTX
WRITE !,"Tasks NOT signaled to shut down."
QUIT
+4 WRITE !!,"Signaling active Tasks to STOP."
+5 DO STPACT
WRITE !,"Done."
+6 QUIT
+7 ;
STPACT ;Set the STOP flag for all ACTIVE Tasks.
+1 NEW ZTI,ZT2
+2 SET ZTI=0
+3 FOR
SET ZTI=$ORDER(^%ZTSCH("TASK",ZTI))
if 'ZTI
QUIT
SET ZT2=$$ASKSTOP^%ZTLOAD(ZTI)
WRITE !,"TASK: ",ZTI," Stop status: ",ZT2
+4 QUIT
+5 ;
QSUB NEW ZTX,ND
+1 FOR
READ !!,"Should active submanagers shut down after finishing their current tasks? NO// ",ZTX:$SELECT($DATA(DTIME)#2:DTIME,1:60)
if '$TEST!("^"[ZTX)!("YESyesNOno"[ZTX)
QUIT
if ZTX'["?"
WRITE $CHAR(7)
WRITE !,"Please answer YES or NO."
+2 if "YESyes"[ZTX&(ZTX]"")
DO GROUP("SSUB(NODE)")
WRITE !,"Okay!",!
+3 QUIT
+4 ;
QUERY ;Query Status Of A Task Manager
+1 if $DATA(%ZTX)[0
QUIT
if %ZTX=""
QUIT
SET %ZTY=0
+2 IF $DATA(^%ZTSCH("STATUS",%ZTX))#2
SET %ZTY=^%ZTSCH("STATUS",%ZTX)
+3 KILL %ZTX
QUIT
+4 ;
NODES ;Return Task Manager Status Nodes
+1 SET %ZTX=""
FOR %ZTY=0:0
SET %ZTX=$ORDER(^%ZTSCH("STATUS",%ZTX))
if %ZTX=""
QUIT
SET %ZTY=%ZTY+1
SET %ZTY(%ZTY)=%ZTX
+2 KILL %ZTX
QUIT
+3 ;
LIVE ;Return Whether A Task Manager Is Live
+1 if $DATA(%ZTX)[0
QUIT
if %ZTX=""
QUIT
SET %ZTY=0
SET U="^"
SET %ZTX1=$HOROLOG
SET %ZTX2=$PIECE(%ZTX,U)
+2 SET %ZTX3=%ZTX1-%ZTX2*86400+$PIECE(%ZTX1,",",2)-$PIECE(%ZTX2,",",2)
+3 IF %ZTX3'<0
SET %ZTY=$SELECT($DATA(^%ZTSCH("RUN"))[0&(%ZTX'["WAIT"):0,%ZTX3<30:1,%ZTX3<120&(%ZTX["PAUSE"):1,1:0)
+4 KILL %ZTX,%ZTX1,%ZTX2,%ZTX3
QUIT
+5 ;
TABLE ;Display Task Manager Table
+1 WRITE !,"JOB NUMBER",?15,"STATUS",?25,"DESCRIPTION",?55,"LAST UPDATED",?75,"LIVE"
+2 WRITE !,"----------",?15,"------",?25,"-----------",?55,"------------",?75,"----"
+3 DO NODES
SET %ZTZ=%ZTY
SET %ZTZ1=0
SET U="^"
SET %H=$HOROLOG
DO YMD^%DTC
SET DT=X
+4 FOR %ZTI=1:1:%ZTZ
SET %ZTX=%ZTY(%ZTI)
DO QUERY
IF %ZTY'=0
WRITE !,%ZTY(%ZTI),?15,$PIECE(%ZTY,U,2),?25,$PIECE(%ZTY,U,3),?55
SET %ZTT=$PIECE(%ZTY,U)
DO T
SET %ZTX=%ZTY
DO LIVE
WRITE ?75,$SELECT(%ZTY:"YES",1:"NO")
IF %ZTY
SET %ZTZ1=%ZTZ1+1
+5 WRITE !?6,"Total:",$JUSTIFY(%ZTZ,3),!?6,"Live :",$JUSTIFY(%ZTZ1,3)
+6 KILL %ZTI,%ZTT,%ZTY,%ZTZ
QUIT
+7 ;
CLEAN ;Cleanup Status Node
+1 KILL ^%ZTSCH("STATUS")
WRITE !,"Done!",!
QUIT
PURGE ;Purge the TASK list of running tasks.
+1 NEW TSK
SET TSK=0
+2 FOR
SET TSK=$ORDER(^%ZTSCH("TASK",TSK))
if TSK'>0
QUIT
IF '$DATA(^%ZTSCH("TASK",TSK,"P"))
KILL ^%ZTSCH("TASK",TSK)
+3 WRITE !,"Done!",!
QUIT
+4 ;
ZTM ;Return Number Of Live Task Managers
+1 NEW %ZTI,%ZTZ,%ZTZ1
+2 DO NODES
SET %ZTZ=%ZTY
SET %ZTZ1=0
FOR %ZTI=1:1:%ZTZ
SET %ZTX=%ZTY(%ZTI)
DO QUERY
IF %ZTY'=0
SET %ZTX=%ZTY
DO LIVE
IF %ZTY
SET %ZTZ1=%ZTZ1+1
+3 SET %ZTY=%ZTZ1
QUIT
+4 ;
UP(X) ;Convert to Uppercase
+1 QUIT $TRANSLATE(X,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
+2 ;
T ;Print Informal-format Conversion Of $H-format Date ; Input: %ZTT, DT.
+1 SET %H=%ZTT
DO 7^%DTC
WRITE $SELECT(DT=X:"TODAY",DT+1=X:"TOMORROW",1:$EXTRACT(X,4,5)_"/"_$EXTRACT(X,6,7)_"/"_$EXTRACT(X,2,3))_" AT "
SET X=$PIECE(%ZTT,",",2)\60
SET %H=X\60
WRITE $EXTRACT(%H+100,2,3)_":"_$EXTRACT(X#60+100,2,3)
+2 ; Output: %ZTT, DT.
KILL %,%D,%H,%M,%Y,X
QUIT
+3 ;