source: WorldVistAEHR/trunk/r/HEALTH_LEVEL_SEVEN-HL/HLOPROC1.m@ 648

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

initial load of WorldVistAEHR

File size: 6.0 KB
Line 
1HLOPROC1 ;ALB/CJM- Process Manager - 10/4/94 1pm
2 ;;1.6;HEALTH LEVEL SEVEN;**126**;Oct 13, 1995
3 ;
4 ;
5GETWORK(PROCESS) ;
6 ;finds a process that needs to be started
7 ;
8 N NAME,IEN,GOTWORK
9 ;this is how HL7 can be stopped via Taskman
10 I $$S^%ZTLOAD D STOPHL7 Q 0
11 S GOTWORK=0
12 S IEN=+$G(PROCESS("IEN"))
13 F S IEN=$O(^HLD(779.3,"C",1,IEN)) Q:IEN=$G(PROCESS("IEN")) I IEN D Q:GOTWORK
14 .N PROC,COUNT,QUEUED,RUNNING
15 .Q:'$$GETPROC(IEN,.PROC)
16 .Q:PROC("VMS SERVICE")
17 .Q:PROC("NAME")="PROCESS MANAGER"
18 .S PROCESS("COUNT")=1
19 .S QUEUED=+$G(^HLC("HL7 PROCESS COUNTS","QUEUED",PROC("NAME")))
20 .S:QUEUED<0 QUEUED=0
21 .S RUNNING=+$G(^HLC("HL7 PROCESS COUNTS","RUNNING",PROC("NAME")))
22 .S:RUNNING<0 RUNNING=0
23 .S COUNT=QUEUED+RUNNING
24 .I COUNT<PROC("MINIMUM") S GOTWORK=1,PROCESS("IEN")=IEN,PROCESS("NAME")=PROC("NAME"),PROCESS("COUNT")=(PROC("MINIMUM")-COUNT) Q
25 .I COUNT<PROC("MAXIMUM"),$$FMDIFF^XLFDT($$NOW^XLFDT,PROC("LAST DT/TM"),2)>PROC("WAIT SECONDS"),'QUEUED S GOTWORK=1,PROCESS("IEN")=IEN,PROCESS("NAME")=PROC("NAME"),PROCESS("COUNT")=1 Q
26 I 'GOTWORK K PROCESS
27 Q GOTWORK
28 ;
29DOWORK(PROCESS) ;
30 ;starts a process
31 ;
32 ;don't start a new task if stopped
33 Q:$$CHKSTOP^HLOPROC
34 ;
35 N ZTRTN,ZTDESC,ZTSAVE,ZTIO,ZTSK,I,ZTDTH
36 S:'$G(PROCESS("COUNT")) PROCESS("COUNT")=1
37 F I=1:1:PROCESS("COUNT") D
38 .S ZTRTN="PROCESS^HLOPROC"
39 .S ZTDESC="HL7 - "_PROCESS("NAME")
40 .S ZTIO=""
41 .S ZTSAVE("PROCNAME")=PROCESS("NAME")
42 .S ZTDTH=$H
43 .D ^%ZTLOAD
44 .I $D(ZTSK) D
45 ..;lock before changing counts
46 ..L +HL7("COUNTING PROCESSES"):20
47 ..I $$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","QUEUED",PROCESS("NAME"))))
48 ..S $P(^HLD(779.3,PROCESS("IEN"),0),"^",6)=$$NOW^XLFDT,^HLTMP("HL7 QUEUED PROCESSES",ZTSK)=$H_"^"_PROCESS("NAME")
49 ..L -HL7("COUNTING PROCESSES")
50 Q
51 ;
52GETPROC(IEN,PROCESS) ;
53 ;given the ien of the HL7 Process Registry entry, returns the entry as a subscripted array in .PROCESS
54 ;
55 ;Output: Function returns 0 on failure, 1 on success
56 ;
57 N NODE
58 S NODE=$G(^HLD(779.3,IEN,0))
59 Q:NODE="" 0
60 S PROCESS("NAME")=$P(NODE,"^")
61 S PROCESS("IEN")=IEN
62 S PROCESS("MINIMUM")=+$P(NODE,"^",3)
63 S PROCESS("MAXIMUM")=+$P(NODE,"^",4)
64 S PROCESS("WAIT SECONDS")=+($P(NODE,"^",5))*60
65 I 'PROCESS("WAIT SECONDS") S PROCESS("WAIT SECONDS")=1000
66 S PROCESS("LAST DT/TM")=$P(NODE,"^",6)
67 S PROCESS("VMS SERVICE")=$P(NODE,"^",15)
68 Q 1
69 ;
70STOPHL7 ;shut down HLO HL7
71 N ZTSK,DOLLARJ
72 ;let other processes know that starting/stopping is underway
73 S $P(^HLD(779.1,1,0),"^",9)=0
74 S ZTSK=""
75 F S ZTSK=$O(^HLTMP("HL7 QUEUED PROCESSES",ZTSK)) Q:ZTSK="" D DQ^%ZTLOAD
76 S DOLLARJ=""
77 F S DOLLARJ=$O(^HLTMP("HL7 RUNNING PROCESSES",DOLLARJ)) Q:DOLLARJ="" S ZTSK=$P($G(^HLTMP("HL7 RUNNING PROCESSES",DOLLARJ)),"^",2) I ZTSK]"" D PCLEAR^%ZTLOAD(ZTSK) I $$ASKSTOP^%ZTLOAD(ZTSK)
78 D CHKQUED
79 Q
80 ;
81STARTHL7 ;start HL7 system, but first do some cleanup
82 ;
83 D RECOUNT()
84 ;
85 ;set the system status flag to active
86 S $P(^HLD(779.1,1,0),"^",9)=1
87 ;
88 ;don't start a process manager if already running
89 L +^HLTMP("PROCESS MANAGER"):1
90 Q:'$T
91 ;
92 ;start the HL7 Process Manager, which will start everything else
93 N PROCESS
94 S PROCESS("NAME")="PROCESS MANAGER"
95 S PROCESS("IEN")=$O(^HLD(779.3,"B","PROCESS MANAGER",0))
96 D DOWORK(.PROCESS)
97 L -^HLTMP("PROCESS MANAGER")
98 Q
99 ;
100QUIT1(COUNT) ;just returns 1 as function value first time around,then 0, insuring that the DO WORK function is called just once
101 I '$G(COUNT) S COUNT=1 Q 1
102 Q 0
103 ;
104CHKDEAD(WORK) ;
105 ;did any process terminate without erasing itself?
106 ;WORK (pass by reference, not required) by the Process Manager that is not used and not required
107 N DOLLARJ S DOLLARJ=""
108 L +HL7("COUNTING PROCESSES"):20
109 Q:'$T
110 F S DOLLARJ=$O(^HLTMP("HL7 RUNNING PROCESSES",DOLLARJ)) Q:DOLLARJ="" I DOLLARJ'=$J L +^HLTMP("HL7 RUNNING PROCESSES",DOLLARJ):0 D:$T
111 .L -^HLTMP("HL7 RUNNING PROCESSES",DOLLARJ)
112 .N PROC
113 .S PROC=$P($G(^HLTMP("HL7 RUNNING PROCESSES",DOLLARJ)),"^",3)
114 .K ^HLTMP("HL7 RUNNING PROCESSES",DOLLARJ)
115 .Q:PROC=""
116 .I $$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","RUNNING",PROC)),-1)<0,$$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","RUNNING",PROC)),1)
117 L -HL7("COUNTING PROCESSES")
118 Q
119CHKQUED ;did any queued task get dequeued without being erased?
120 N PROC,JOB
121 L +HL7("COUNTING PROCESSES"):20
122 Q:'$T
123 S JOB=""
124 F S JOB=$O(^HLTMP("HL7 QUEUED PROCESSES",JOB)) Q:JOB="" I '$$QUEUED(JOB) D
125 .N PROC
126 .S PROC=$P($G(^HLTMP("HL7 QUEUED PROCESSES",JOB)),"^",2)
127 .I PROC]"",$$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","QUEUED",PROC)),-1)<0,$$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","QUEUED",PROC)),1)
128 .K ^HLTMP("HL7 QUEUED PROCESSES",JOB)
129 L -HL7("COUNTING PROCESSES")
130 Q
131 ;
132QUEUED(TASK) ;
133 ;function returns 0 if ZTSK is not queued to run, 1 if it is
134 N ZTSK
135 S ZTSK=TASK
136 D ISQED^%ZTLOAD
137 Q:ZTSK(0) 1
138 Q 0
139 ;
140CNTLIVE ;count the running processes
141 N JOB,COUNTS,PROC
142 L +HL7("COUNTING PROCESSES"):20
143 Q:'$T
144 S JOB=""
145 F S JOB=$O(^HLTMP("HL7 RUNNING PROCESSES",JOB)) Q:JOB="" S PROC=$P($G(^HLTMP("HL7 RUNNING PROCESSES",JOB)),"^",3) I PROC]"" S COUNTS(PROC)=$G(COUNTS(PROC))+1
146 S PROC="" F S PROC=$O(COUNTS(PROC)) Q:PROC="" S ^HLC("HL7 PROCESS COUNTS","RUNNING",PROC)=COUNTS(PROC)
147 S PROC="" F S PROC=$O(^HLC("HL7 PROCESS COUNTS","RUNNING",PROC)) Q:PROC="" S ^HLC("HL7 PROCESS COUNTS","RUNNING",PROC)=+$G(COUNTS(PROC))
148 L -HL7("COUNTING PROCESSES")
149 Q
150 ;
151CNTQUED ;count the queued tasks
152 N JOB,COUNTS,PROC
153 L +HL7("COUNTING PROCESSES"):20
154 Q:'$T
155 S JOB=""
156 F S JOB=$O(^HLTMP("HL7 QUEUED PROCESSES",JOB)) Q:JOB="" S PROC=$P($G(^HLTMP("HL7 QUEUED PROCESSES",JOB)),"^",2) I PROC]"" S COUNTS(PROC)=$G(COUNTS(PROC))+1
157 S PROC="" F S PROC=$O(COUNTS(PROC)) Q:PROC="" S ^HLC("HL7 PROCESS COUNTS","QUEUED",PROC)=COUNTS(PROC)
158 S PROC="" F S PROC=$O(^HLC("HL7 PROCESS COUNTS","QUEUED",PROC)) Q:PROC="" S ^HLC("HL7 PROCESS COUNTS","QUEUED",PROC)=+$G(COUNTS(PROC))
159 L -HL7("COUNTING PROCESSES")
160 Q
161 ;
162RECOUNT(RECOUNT) ;check that the processes that are supposed to be running actually are, same for the queued processes
163 ;Input:
164 ; RECOUNT (pass by reference, optional) not used, but passed in by the process manager
165 ;
166 ;
167 ;check for processes that are supposed to be running or queued but aren't
168 D CHKDEAD(),CHKQUED
169 ;
170 ;recount the processes
171 D CNTLIVE,CNTQUED
172 Q
Note: See TracBrowser for help on using the repository browser.