source: WorldVistAEHR/trunk/r/KERNEL-XU-A4A7-USC-XG-XLF-XNOA-XPD-XQ-XVIR-ZI-ZOSF-ZOSV-ZT-ZU-%Z-XIP--XQAB--XUC--XUR--ZIN--ZTED/_ZTM.m@ 738

Last change on this file since 738 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 6.2 KB
Line 
1%ZTM ;SEA/RDS-TaskMan: Manager, Part 1 (Main Loop) ;1/9/2006
2 ;;8.0;KERNEL;**24,36,64,67,118,127,136,275,355**;JUL 10, 1995;Build 9
3 ;
4 ;%ZTCHK is set to 1 @ top of SCHQ, set to 0 if send a task to SM
5LOOP ;Taskman's Main Loop
6 F %ZTLOOP=0:1 S %ZTLOOP=%ZTLOOP#16 D CHECK,SCHQ,IDLE:%ZTCHK
7 S %ZTFALL="" G LOOP
8 ;
9CHECK ;LOOP--Check Status And Update Loop Data
10 ;Do CHECK if sent a new job or %ZTLOOP=0.
11 Q:%ZTLOOP&$G(%ZTCHK)
12 I $D(^%ZTSCH("STOP","MGR",%ZTPAIR)) G HALT^%ZTM0
13 S ^%ZTSCH("RUN")=$H,ZTPAIR="",%ZTIME=$$H3($H)
14 I $D(^%ZTSCH("WAIT","MGR"))#2 D STATUS("WAIT","Taskman Waiting") H 5 G CHECK
15 ;
16 I $D(^%ZTSCH("UPDATE",$J))[0 D UPDATE^%ZTM5
17 I %ZTVLI D STATUS("PAUSE","Logons Inhibited") H 60 G CHECK ;Set in %ZTM5
18 I @%ZTNLG D INHIBIT^%ZTM5(1),STATUS("PAUSE","No Signons Allowed") H 60 G CHECK
19 I $G(^%ZIS(14.5,"LOGON",%ZTVOL)) D INHIBIT^%ZTM5(0) ;Check field
20 I $D(ZTREQUIR)#2 D STATUS("PAUSE","Required link to "_ZTREQUIR_" is down.") H 60 D REQUIR^%ZTM5 G CHECK
21 ;
22 I $D(^%ZTSCH("LINK"))#2,$$DIFF($H,^("LINK"))>900 D LINK^%ZTM3
23 ;
24 S %ZTRUN=%ZTVMJ>$$ACTJ^%ZOSV ;Check for job limit
25 ;
26 I %ZTPFLG("BAL")]"" D I ZTOVERLD G CHECK
27 . S ZTOVERLD=0
28 . Q:%ZTPFLG("LBT")>%ZTIME S %ZTPFLG("LBT")=%ZTIME+%ZTPFLG("BI")
29 . D BALANCE^%ZTM6 Q:'ZTOVERLD
30 . D STATUS("BALANCE","Waiting to balance the load.")
31 . ;Start submanagers for C list work
32 . I $D(^%ZTSCH("C",%ZTPAIR))>9,%ZTRUN D NEWJOB(%ZTUCI,%ZTVOL,"")
33 . N T F T=1:1:%ZTPFLG("BI") H 1 Q:$$STOPWT^%ZTM6()
34 . Q
35 ;
36 I %ZTRUN D STATUS("RUN","Main Loop")
37 I '%ZTRUN D STATUS("RUN","Taskman Job Limit Reached"),CHECK^%ZTM6
38 Q
39 ;
40STATUS(ST,MSG) ;Record TM status
41 S ^%ZTSCH("STATUS",$J)=$H_"^"_ST_"^"_$G(%ZTPAIR)_"^"_MSG
42 Q
43 ;
44TLOCK(M,T) ;Lock a time node
45 I M>0 L +^%ZTSCH(ZTDTH):0 Q $T
46 L -^%ZTSCH(ZTDTH) Q
47 ;
48SCHQ ;LOOP--Check Schedule List
49 S %ZTIME=$$H3($H),ZTDTH=0,%ZTCHK=1,IO=""
50S1 S ZTDTH=$O(^%ZTSCH(ZTDTH)),ZTSK=0 Q:(ZTDTH>%ZTIME) Q:('ZTDTH)!(ZTDTH'?1.N) I +ZTDTH<0 K ^%ZTSCH(ZTDTH) G S1
51 I '$$TLOCK(1,ZTDTH) G S1
52S2 S ZTSK=$O(^%ZTSCH(ZTDTH,ZTSK)) I ZTSK="" D TLOCK(-1,ZTDTH) G S1
53 S ZTST=$G(^%ZTSCH(ZTDTH,ZTSK))
54 ;Get task lock then release time lock
55 L +^%ZTSK(ZTSK):0 G S2:'$T
56 K ^%ZTSCH(ZTDTH,ZTSK) D TLOCK(-1,ZTDTH)
57 ;Count tasks
58 S %ZTMON(%ZTMON)=$G(%ZTMON(%ZTMON))+1
59 I $D(^%ZTSK(ZTSK,0))[0 D TSKSTAT("I") L -^%ZTSK(ZTSK) G S2
60 I $L($P($G(^%ZTSK(ZTSK,.1)),U,10)) D TSKSTAT("D","Stopped") L -^%ZTSK(ZTSK) G S2
61 D ^%ZTM1
62 I %ZTREJCT L -^%ZTSK(ZTSK) G S2
63 ;
64SEND ;Send Task To Submanager
65 S %ZTCHK=0,ZTPAIR=""
66 I ZTDVOL'=%ZTVOL D XLINK^%ZTM2 G:'ZTJOBIT SCHX
67 ;Clear before job cmd
68 I (ZTYPE'="C")&(%ZTNODE[ZTNODE) D
69 . D TSKSTAT(3,"Placed on JOB List")
70 . S ^%ZTSCH("JOB",ZTDTH,ZTSK)=IO ;No other lock on JOB
71 E D
72 . D TSKSTAT("M","Placed on C List")
73 . S ZTPAIR=ZTDVOL_$S($L(ZTNODE):":"_ZTNODE,1:"")
74 . S ^%ZTSCH("C",ZTPAIR,ZTDTH,ZTSK)=IO
75 ;
76 L -^%ZTSK(ZTSK)
77 ;
78 ;I '$D(^%ZTSCH("STOP","SUB",%ZTPAIR)),'$$OOS(ZTPAIR) D NEWJOB(ZTUCI,ZTDVOL,ZTNODE,ZTYPE,ZTPAIR)
79 ;I '$D(^%ZTSCH("STOP","SUB",%ZTPAIR)),(ZTYPE="C"!(%ZTRUN&$$NEWSUB)),'$$OOS(ZTPAIR) D
80 ;. I 1 X %ZTJOB H %ZTSLO I '$T X %ZTJOB H %ZTSLO
81 ;. Q
82 I (ZTYPE="C"!(%ZTRUN&$$NEWSUB)),'$$OOS(ZTPAIR) D NEWJOB(ZTUCI,ZTDVOL,ZTNODE)
83SCHX L K ZTREP Q
84 ;
85IDLE ;LOOP--DEV Node Maintenance; Backup JOB Commands
86 S (ZTREC,ZTCVOL)="" H 1 ;This is the main hang
87 I %ZTMON("NEXT")'>%ZTIME D MON ;See if time to update %ZTMON
88 Q:'%ZTRUN ;Only do IDLE work if not at job limit
89 I $D(^%ZTSCH("STOP","MGR",%ZTPAIR)) Q
90 ;job off a new submanager if MIN count < # SUBs
91 I $$NEWSUB D NEWJOB(%ZTUCI,%ZTVOL,"")
92 L +^%ZTSCH("IDLE",%ZTPAIR):0 Q:'$T D IDLE1 L -^%ZTSCH("IDLE",%ZTPAIR)
93 Q
94IDLE1 ;only proceed with idle work if 60 seconds since last check
95 I $$DIFF(%ZTIME,^%ZTSCH("IDLE"),1)<60 Q
96 I %ZTPFLG("XUSCNT") D TOUCH^XUSCNT
97 D I1,I2,I5,I6
98 S ^%ZTSCH("IDLE")=%ZTIME
99 Q
100 ;
101I1 ;clear out old DEV nodes
102 N X,%ZTIO S %ZTIO=""
103 F S %ZTIO=$O(^%ZTSCH("DEV",%ZTIO)) Q:%ZTIO="" L ^%ZTSCH("DEV",%ZTIO):0 I $T D L -^%ZTSCH("DEV",%ZTIO)
104 . S X=$G(^%ZTSCH("DEV",%ZTIO)) Q:'$L(X)
105 . I $$DIFF(%ZTIME,X,1)>120 K ^%ZTSCH("DEV",%ZTIO)
106 . Q
107 Q
108 ;
109I2 ;job new submanagers cross-volume for each unfinished C list
110 I $D(^%ZTSCH("C")) D
111 . N Y,ZTUCI,ZTVOL,ZTNODE,$ETRAP,$ESTACK S $ET="S $EC="""" D ERCL^%ZTM2"
112 . S ZTVOL="" F S ZTVOL=$O(^%ZTSCH("C",ZTVOL)) Q:ZTVOL="" D
113 .. I $O(^%ZTSCH("C",ZTVOL,0))="" Q
114 .. S ZTNODE="",ZTDVOL=ZTVOL S:ZTDVOL[":" ZTNODE=$P(ZTDVOL,":",2),ZTDVOL=$P(ZTDVOL,":")
115 .. S X=$G(^%ZTSCH("C",ZTVOL))
116 .. I $D(^%ZTSCH("LINK",ZTDVOL))!(X>9)!$$OOS(ZTVOL) Q
117 .. S ^%ZTSCH("C",ZTVOL)=X+1
118 .. S ZTUCI=$O(^%ZIS(14.6,"AV",ZTDVOL,""))
119 .. D NEWJOB(ZTUCI,ZTDVOL,ZTNODE)
120 .. Q
121 . Q
122 Q
123 ;
124I4 ;job off a new submanager if the Job List still has tasks
125 I $D(^%ZTSCH("JOB"))>9 D NEWJOB(%ZTUCI,%ZTVOL,"")
126 Q
127 ;
128I5 ;Clean up %ZTSCH
129 S ZTDTH="0,0" F S ZTDTH=$O(^%ZTSCH(ZTDTH)) Q:ZTDTH'["," D
130 . N ZTSK,X L +^%ZTSCH(ZTDTH):0 Q:'$T
131 . S ZTSK=$O(^%ZTSCH(ZTDTH,0)) I ZTSK>0 S X=^(ZTSK),^%ZTSCH($$H3(ZTDTH),ZTSK)=X K ^%ZTSCH(ZTDTH,ZTSK)
132 . L -^%ZTSCH(ZTDTH)
133 . Q
134 Q
135 ;
136I6 ;Check on persistent jobs.
137 S ZTSK=0 F S ZTSK=$O(^%ZTSCH("TASK",ZTSK)) Q:ZTSK'>0 D:$D(^%ZTSCH("TASK",ZTSK,"P"))
138 . L +^%ZTSCH("TASK",ZTSK):0 E Q ;Still running
139 . L -^%ZTSCH("TASK",ZTSK)
140 . D REQP^%ZTLOAD3(ZTSK) ;START NEW TASK.
141 K %ZTVS Q
142 ;
143MON ;Set Next %ZTMON each Hour
144 S %ZTMON=$P($H,",",2)\3600,%ZTMON(%ZTMON)=0
145 S %ZTMON("NEXT")=($H*86400)+(%ZTMON+1*3600)
146 D HOUR^%ZTM5
147 I %ZTMON("DAY")<+$H D DAY^%ZTM5
148 Q
149 ;
150NEWJOB(ZTUCI,ZTDVOL,ZTNODE) ;Start a new Job
151 S ZTUCI=$G(ZTUCI),ZTDVOL=$G(ZTDVOL),ZTNODE=$G(ZTNODE)
152 X %ZTJOB H %ZTSLO ;If job doesn't work, will catch next time.
153 Q
154 ;
155DIFF(N,O,T) ;Diff in sec.
156 Q:$G(T) N-O ;For new seconds times
157 Q N-O*86400-$P(O,",",2)+$P(N,",",2)
158 ;
159OOS(BV) ;Check if Box-Volume is Out Of Service, Return 1 if OOS.
160 Q:BV="" 0 N %
161 S %=$O(^%ZIS(14.7,"B",BV,0)),%=$G(^%ZIS(14.7,+%,0))
162 Q:%="" 1 Q $P(%,U,11)=1
163 ;
164H3(%) ;Convert $H to seconds.
165 Q 86400*%+$P(%,",",2)
166H0(%) ;Covert from seconds to $H
167 Q (%\86400)_","_(%#86400)
168SUBOK() ;Check if sub's are starting, return 1 if OK
169 S ^%ZTSCH("SUB",%ZTPAIR,0)=($G(^%ZTSCH("SUB",%ZTPAIR,0))+1)_"^"_$H
170 Q ^%ZTSCH("SUB",%ZTPAIR,0)<10
171 ;
172NEWSUB() ;See if we need a new submanager
173 N SUBS
174 L +^%ZTSCH("SUB",%ZTPAIR):0 S SUBS=^%ZTSCH("SUB",%ZTPAIR)
175 L -^%ZTSCH("SUB",%ZTPAIR)
176 I SUBS<%ZTPFLG("MINSUB") Q 1
177 Q 0
178 ;
179TSKSTAT(CODE,MSG) ; Update task's status
180 S $P(^%ZTSK(ZTSK,.1),U,1,3)=$G(CODE)_U_$H_U_$G(MSG)
181 Q
Note: See TracBrowser for help on using the repository browser.