source: cprs/branches/tmg-cprs/m_files/TMGMKU.m@ 1117

Last change on this file since 1117 was 796, checked in by Kevin Toppenberg, 14 years ago

Initial upload

File size: 10.2 KB
Line 
1TMGMKU ;TMG/kst/Custom version of ZTMKU ;03/25/06
2 ;;1.0;TMG-LIB;**1**;11/01/04
3
4 ;"ZTMKU code -- NON-INTERACTIVE versions of standard code.
5 ;"=============================================================================
6 ;"Kevin Toppenberg, MD 11-04
7 ;"
8 ;"Purpose:
9 ;"
10 ;"This library will provide optional NON-INTERACTIVE versions of standard code.
11 ;"
12 ;"ZTMKU code
13 ;"Apparent Callable points:
14 ;" (See below about optional "INFO" parameter)
15 ;" SSUB(NODE) ;Stop sub-managers
16 ;" SMAN(NODE) ;stop managers
17 ;" RUN(INFO) ;Remove Task Managers From WAIT State
18 ;" UPDATE(INFO) ;Have Managers Do an parameter Update
19 ;" WAIT(INFO) ;Put Task Managers In WAIT State
20 ;" STOP(INFO) ;Shut Down Task Managers
21 ;" QUERY ;Query Status Of A Task Manager
22 ;" NODES ;Return Task Manager Status Nodes
23 ;" LIVE ;Return Whether A Task Manager Is Live
24 ;" TABLE(INFO) ;Display Task Manager Table
25 ;" CLEAN(INFO) ;Cleanup Status Node
26 ;" PURGE(INFO) ;Purge the TASK list of running tasks.
27 ;" ZTM ;Return Number Of Live Task Managers
28 ;"
29 ;"Dependancies:
30 ;" if TMGDEBUG defined, then requires TMGDEBUG.m
31 ;"=============================================================================
32
33ZTMKU ;SEA/RDS-Taskman: Option, ZTMWAIT/RUN/STOP ;11/04/99 15:05
34 ;;8.0;KERNEL;**118,127,275**;Jul 10, 1995
35 ;
36
37 ;"K. Toppenberg's changes made November, 2004
38 ;"
39 ;"Input:
40 ;" Note: INFO variable is completely an OPTIONAL parameter.
41 ;" If not supplied, interactive mode used
42 ;" INFO("SILENT-OUTPUT") -- 1 = output is supressed.
43 ;" INFO("SILENT-INPUT") -- 1 = User-interactive input is supressed.
44 ;"
45 ;" ** if in SILENT-INPUT mode, THEN the following data should be supplied, if the
46 ;" relevent function is being called.
47 ;" ----------------------
48 ;" INFO("CONTINUE") -- Should contain the answer the user would enter for question:
49 ;" Are you sure you want to stop TaskMan?
50 ;" Used in STOP^TMGMKU(INFO)
51 ;" INFO("SUBMANAGERS") -- Answer to: Should active submanagers shut down after finishing their current tasks?
52 ;" Used in STOP^TMGMKU(INFO)
53 ;"Output:
54 ;" If in SILENT-OUTPUT mode, then output that would normally go to the screen, will be routed to this array
55 ;" NOTE: INFO SHOULD BE PASSED BY REFERENCE if user wants this information passed back out.
56 ;" INFO("TEXT","LINES")=Number of output lines
57 ;" INFO("TEXT",1)= 1st output line
58 ;" INFO("TEXT",2)= 2nd output line, etc...
59 ;
60 ;
61 Q
62
63INIT
64 IF $DATA(TMGDEBUG) DO DebugEntry^TMGDEBUG(.DBINDENT,"INIT^TMGMKU")
65 IF $DATA(SILNTOUT)=0 KILL INFO("TEXT") ;//kt
66 ;
67 ;"Note: this establishes a variable with global-scope. ... And no one kills it...
68 SET SILNTOUT=$GET(INFO("SILENT-OUTPUT"),0) ;//kt
69 SET SILENTIN=$GET(INFO("SILENT-INPUT"),0) ;//KT
70 IF $DATA(TMGDEBUG) DO DebugExit^TMGDEBUG(.DBINDENT,"INIT^TMGMKU")
71 ;
72 QUIT
73
74
75 ;
76 ;"=============================================================================
77SSUB(NODE) ;Stop sub-managers
78 D SS(1,"SUB",NODE) Q
79 ;"=============================================================================
80SMAN(NODE) ;stop managers
81 D SS(1,"MGR",NODE) Q
82 ;
83 ;"=============================================================================
84SS(MD,GR,NODE) ;Set/clear STOP nodes.
85 S GR=$G(GR,"MGR") S:"MGR_SUB_"'[GR GR="MGR"
86 I MD=1 S ^%ZTSCH("STOP",GR,NODE)=$H D WS(0,GR)
87 I MD=0 K ^%ZTSCH("STOP",GR,NODE)
88 Q
89 ;
90 ;"=============================================================================
91WS(MD,GR) ;Set/Clear Wait state
92 S GR=$G(GR,"MGR") S:"MGR_SUB_"'[GR GR="MGR"
93 I MD=1 S ^%ZTSCH("WAIT",GR)=$H ;set wait state
94 I MD=0 K ^%ZTSCH("WAIT",GR) ;Clear wait
95 Q
96 ;
97 ;"=============================================================================
98GROUP(CALL) ;Do CALL for each node, use NODE as the parameter
99 N J,ND,NODE
100 F J=0:0 S J=$O(^%ZTSCH("STATUS",J)) Q:J="" S ND=$G(^(J)),NODE=$P(ND,"^",3) D @CALL
101 Q
102 ;
103 ;"=============================================================================
104OPT(MD) ;Disable/Enable option prosessing
105 I MD=1 S ^%ZTSCH("NO-OPTION")=""
106 I MD=0 K ^%ZTSCH("NO-OPTION")
107 Q
108 ;
109 ;"=============================================================================
110RUN(INFO) ;Remove Task Managers From WAIT State
111 D WS(0,"MGR"),WS(0,"SUB") K ^%ZTSCH("STOP")
112
113 DO INIT
114 DO OUTP^TMGQIO(SILNTOUT,"!","Done!","!")
115 Q
116 ;
117 ;"=============================================================================
118UPDATE(INFO) ;Have Managers Do an parameter Update
119 K ^%ZTSCH("UPDATE")
120 DO INIT
121 DO OUTP^TMGQIO(SILNTOUT,"!","Done!","!")
122 Q
123 ;
124 ;"=============================================================================
125WAIT(INFO) ;Put Task Managers In WAIT State
126 DO INIT
127 D WS(1,"MGR")
128 DO OUTP^TMGQIO(SILNTOUT,"!","TaskMan now in 'WAIT STATE'",$C(7),"!")
129 D QSUB
130 Q
131 ;
132 ;"=============================================================================
133STOP(INFO) ;Shut Down Task Managers
134 IF $DATA(TMGDEBUG) DO DebugEntry^TMGDEBUG(.DBINDENT,"STOP^TMGMKU")
135 DO INIT
136 N ZTX,ND,J
137 DO INIT
138 F DO Q:'$T!("^YESyesNOno"[ZTX)!(SILENTIN=1)
139 . DO OUTP^TMGQIO(SILNTOUT,"!","!","Are you sure you want to stop TaskMan? NO// ")
140 . IF $DATA(TMGDEBUG) DO DebugMsg^TMGDEBUG(.DBINDENT,"Starting Question Loop")
141 . DO INP^TMGQIO(.ZTX,SILENTIN,$G(DTIME,60),$GET(INFO("CONTINUE")))
142 . IF $GET(ZTX)="" SET ZTX="NO"
143 . Q:'$T!("^YESyesNOno"[ZTX)!(SILENTIN=1)
144 . IF ZTX'["?" DO OUTP^TMGQIO(SILNTOUT,$C(7))
145 . DO OUTP^TMGQIO(SILNTOUT,"!","Answer YES to shut down all Task Managers on current the volume set.")
146 IF $DATA(TMGDEBUG) DO DebugMsg^TMGDEBUG(.DBINDENT,"Processing input")
147 I "YESyes"[ZTX DO
148 . DO OUTP^TMGQIO(SILNTOUT,"!","Shutting down TaskMan.")
149 . D GROUP("SMAN(NODE)")
150 . ;"F J=0:0 S J=$O(^%ZTSCH("STATUS",J)) Q:J="" S ND=$G(^(J)) D SMAN($P(ND,U,3))
151 . ;"Q
152 . D QSUB
153 ELSE DO
154 . DO OUTP^TMGQIO(SILNTOUT,"!","TaskMan NOT shut down.")
155 IF $DATA(TMGDEBUG) DO DebugExit^TMGDEBUG(.DBINDENT,"STOP^TMGMKU")
156 Q
157 ;
158 ;"=============================================================================
159QSUB
160 IF $DATA(TMGDEBUG) DO DebugEntry^TMGDEBUG(.DBINDENT,"QSUB^TMGMKU")
161 N ZTX,ND
162 F DO Q:'$T!("^YESyesNOno"[ZTX)!(SILENTIN=1)
163 . DO OUTP^TMGQIO(SILNTOUT,"!","!","Should active submanagers shut down after finishing their current tasks? NO// ")
164 . IF $DATA(TMGDEBUG) DO DebugMsg^TMGDEBUG(.DBINDENT,"Auto answer=",$GET(INFO("SUBMANAGERS")))
165 . DO INP^TMGQIO(.ZTX,SILENTIN,$S($D(DTIME)#2:DTIME,1:60),$GET(INFO("SUBMANAGERS")))
166 . IF ZTX="" SET ZTX="NO"
167 . Q:'$T!("^YESyesNOno"[ZTX)!(SILENTIN=1)
168 . IF ZTX'["?" DO OUTP^TMGQIO(SILNTOUT,$C(7))
169 . DO OUTP^TMGQIO(SILNTOUT,"!","Please answer YES or NO..")
170 I "YESyes"[ZTX DO
171 . DO GROUP("SSUB(NODE)")
172 . DO OUTP^TMGQIO(SILNTOUT,"!","Okay!","!")
173 IF $DATA(TMGDEBUG) DO DebugExit^TMGDEBUG(.DBINDENT,"QSUB^TMGMKU")
174 Q
175 ;
176 ;"=============================================================================
177QUERY ;Query Status Of A Task Manager
178 Q:$D(%ZTX)[0 Q:%ZTX="" S %ZTY=0
179 I $D(^%ZTSCH("STATUS",%ZTX))#2 S %ZTY=^%ZTSCH("STATUS",%ZTX)
180 K %ZTX Q
181 ;
182 ;"=============================================================================
183NODES ;Return Task Manager Status Nodes
184 S %ZTX="" F %ZTY=0:0 S %ZTX=$O(^%ZTSCH("STATUS",%ZTX)) Q:%ZTX="" S %ZTY=%ZTY+1,%ZTY(%ZTY)=%ZTX
185 K %ZTX Q
186 ;
187 ;"=============================================================================
188LIVE ;Return Whether A Task Manager Is Live
189 Q:$D(%ZTX)[0 Q:%ZTX="" S %ZTY=0,U="^",%ZTX1=$H,%ZTX2=$P(%ZTX,U)
190 S %ZTX3=%ZTX1-%ZTX2*86400+$P(%ZTX1,",",2)-$P(%ZTX2,",",2)
191 I %ZTX3'<0 S %ZTY=$S($D(^%ZTSCH("RUN"))[0&(%ZTX'["WAIT"):0,%ZTX3<30:1,%ZTX3<120&(%ZTX["PAUSE"):1,1:0)
192 K %ZTX,%ZTX1,%ZTX2,%ZTX3 Q
193 ;
194 ;"=============================================================================
195TABLE(INFO) ;Display Task Manager Table
196 IF $DATA(TMGDEBUG) DO DebugEntry^TMGDEBUG(.DBINDENT,"TABLE^TMGMKU")
197 DO INIT
198 DO OUTP^TMGQIO(SILNTOUT,"!","NUMBER","?15","STATUS","?25","DESCRIPTION","?55","LAST UPDATED","?75","LIVE")
199 DO OUTP^TMGQIO(SILNTOUT,"!","------","?15","------","?25","-----------","?55","------------","?75","----")
200 D NODES S %ZTZ=%ZTY,%ZTZ1=0,U="^",%H=$H D YMD^%DTC S DT=X
201 F %ZTI=1:1:%ZTZ DO
202 . S %ZTX=%ZTY(%ZTI)
203 . D QUERY
204 . I %ZTY'=0 DO
205 . . DO OUTP^TMGQIO(SILNTOUT,"!",%ZTY(%ZTI),"?15",$P(%ZTY,U,2),"?25",$P(%ZTY,U,3),"?55")
206 . . S %ZTT=$P(%ZTY,U)
207 . . D T
208 . . S %ZTX=%ZTY
209 . . D LIVE
210 . . DO OUTP^TMGQIO(SILNTOUT,"?75",$S(%ZTY:"YES",1:"NO"))
211 . . I %ZTY S %ZTZ1=%ZTZ1+1
212 DO OUTP^TMGQIO(SILNTOUT,"!","?6","Total:",$J(%ZTZ,3),"!")
213 DO OUTP^TMGQIO(SILNTOUT,"?6","Live :",$J(%ZTZ1,3))
214 K %ZTI,%ZTT,%ZTY,%ZTZ
215 IF $DATA(TMGDEBUG) DO DebugExit^TMGDEBUG(.DBINDENT,"TABLE^TMGMKU")
216 Q
217 ;
218 ;
219 ;"=============================================================================
220CLEAN(INFO) ;Cleanup Status Node
221 IF $DATA(TMGDEBUG) DO DebugEntry^TMGDEBUG(.DBINDENT,"CLEAN^TMGMKU")
222 DO INIT
223 K ^%ZTSCH("STATUS")
224 DO OUTP^TMGQIO(SILNTOUT,"!","Done!","!")
225 ;
226 IF $DATA(TMGDEBUG) DO DebugExit^TMGDEBUG(.DBINDENT,"CLEAN^TMGMKU")
227 Q
228 ;
229 ;
230 ;"=============================================================================
231PURGE(INFO) ;Purge the TASK list of running tasks.
232 IF $DATA(TMGDEBUG) DO DebugEntry^TMGDEBUG(.DBINDENT,"PURGE^TMGMKU")
233 DO INIT
234 N TSK S TSK=0
235 F S TSK=$O(^%ZTSCH("TASK",TSK)) Q:TSK'>0 I '$D(^%ZTSCH("TASK",TSK,"P")) K ^%ZTSCH("TASK",TSK)
236 DO OUTP^TMGQIO(SILNTOUT,"!","Done!","!")
237 IF $DATA(TMGDEBUG) DO DebugExit^TMGDEBUG(.DBINDENT,"CLEAN^TMGMKU")
238 Q
239 ;
240 ;
241 ;"=============================================================================
242ZTM ;Return Number Of Live Task Managers
243 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
244 S %ZTY=%ZTZ1 K %ZTI,%ZTZ,%ZTZ1 Q
245 ;
246 ;"=============================================================================
247T ;Print Informal-format Conversion Of $H-format Date ; Input: %ZTT, DT.
248 IF $DATA(TMGDEBUG) DO DebugEntry^TMGDEBUG(.DBINDENT,"T^TMGMKU")
249 S %H=%ZTT
250 D 7^%DTC
251 DO OUTP^TMGQIO(SILNTOUT,$S(DT=X:"TODAY",DT+1=X:"TOMORROW",1:$E(X,4,5)_"/"_$E(X,6,7)_"/"_$E(X,2,3))_" AT ")
252 S X=$P(%ZTT,",",2)\60
253 S %H=X\60
254 DO OUTP^TMGQIO(SILNTOUT,$E(%H+100,2,3)_":"_$E(X#60+100,2,3))
255 K %,%D,%H,%M,%Y,X
256 ;
257 IF $DATA(TMGDEBUG) DO DebugExit^TMGDEBUG(.DBINDENT,"T^TMGMKU")
258 Q ; Output: %ZTT, DT.
259 ;
260 ;"=============================================================================
Note: See TracBrowser for help on using the repository browser.