Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: HLOPROC1

HLOPROC1.m

Go to the documentation of this file.
  1. HLOPROC1 ;ALB/CJM- Process Manager - 10/4/94 1pm
  1. ;;1.6;HEALTH LEVEL SEVEN;**126**;Oct 13, 1995
  1. ;
  1. ;
  1. GETWORK(PROCESS) ;
  1. ;finds a process that needs to be started
  1. ;
  1. N NAME,IEN,GOTWORK
  1. ;this is how HL7 can be stopped via Taskman
  1. I $$S^%ZTLOAD D STOPHL7 Q 0
  1. S GOTWORK=0
  1. S IEN=+$G(PROCESS("IEN"))
  1. F S IEN=$O(^HLD(779.3,"C",1,IEN)) Q:IEN=$G(PROCESS("IEN")) I IEN D Q:GOTWORK
  1. .N PROC,COUNT,QUEUED,RUNNING
  1. .Q:'$$GETPROC(IEN,.PROC)
  1. .Q:PROC("VMS SERVICE")
  1. .Q:PROC("NAME")="PROCESS MANAGER"
  1. .S PROCESS("COUNT")=1
  1. .S QUEUED=+$G(^HLC("HL7 PROCESS COUNTS","QUEUED",PROC("NAME")))
  1. .S:QUEUED<0 QUEUED=0
  1. .S RUNNING=+$G(^HLC("HL7 PROCESS COUNTS","RUNNING",PROC("NAME")))
  1. .S:RUNNING<0 RUNNING=0
  1. .S COUNT=QUEUED+RUNNING
  1. .I COUNT<PROC("MINIMUM") S GOTWORK=1,PROCESS("IEN")=IEN,PROCESS("NAME")=PROC("NAME"),PROCESS("COUNT")=(PROC("MINIMUM")-COUNT) Q
  1. .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
  1. I 'GOTWORK K PROCESS
  1. Q GOTWORK
  1. ;
  1. DOWORK(PROCESS) ;
  1. ;starts a process
  1. ;
  1. ;don't start a new task if stopped
  1. Q:$$CHKSTOP^HLOPROC
  1. ;
  1. N ZTRTN,ZTDESC,ZTSAVE,ZTIO,ZTSK,I,ZTDTH
  1. S:'$G(PROCESS("COUNT")) PROCESS("COUNT")=1
  1. F I=1:1:PROCESS("COUNT") D
  1. .S ZTRTN="PROCESS^HLOPROC"
  1. .S ZTDESC="HL7 - "_PROCESS("NAME")
  1. .S ZTIO=""
  1. .S ZTSAVE("PROCNAME")=PROCESS("NAME")
  1. .S ZTDTH=$H
  1. .D ^%ZTLOAD
  1. .I $D(ZTSK) D
  1. ..;lock before changing counts
  1. ..L +HL7("COUNTING PROCESSES"):20
  1. ..I $$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","QUEUED",PROCESS("NAME"))))
  1. ..S $P(^HLD(779.3,PROCESS("IEN"),0),"^",6)=$$NOW^XLFDT,^HLTMP("HL7 QUEUED PROCESSES",ZTSK)=$H_"^"_PROCESS("NAME")
  1. ..L -HL7("COUNTING PROCESSES")
  1. Q
  1. ;
  1. GETPROC(IEN,PROCESS) ;
  1. ;given the ien of the HL7 Process Registry entry, returns the entry as a subscripted array in .PROCESS
  1. ;
  1. ;Output: Function returns 0 on failure, 1 on success
  1. ;
  1. N NODE
  1. S NODE=$G(^HLD(779.3,IEN,0))
  1. Q:NODE="" 0
  1. S PROCESS("NAME")=$P(NODE,"^")
  1. S PROCESS("IEN")=IEN
  1. S PROCESS("MINIMUM")=+$P(NODE,"^",3)
  1. S PROCESS("MAXIMUM")=+$P(NODE,"^",4)
  1. S PROCESS("WAIT SECONDS")=+($P(NODE,"^",5))*60
  1. I 'PROCESS("WAIT SECONDS") S PROCESS("WAIT SECONDS")=1000
  1. S PROCESS("LAST DT/TM")=$P(NODE,"^",6)
  1. S PROCESS("VMS SERVICE")=$P(NODE,"^",15)
  1. Q 1
  1. ;
  1. STOPHL7 ;shut down HLO HL7
  1. N ZTSK,DOLLARJ
  1. ;let other processes know that starting/stopping is underway
  1. S $P(^HLD(779.1,1,0),"^",9)=0
  1. S ZTSK=""
  1. F S ZTSK=$O(^HLTMP("HL7 QUEUED PROCESSES",ZTSK)) Q:ZTSK="" D DQ^%ZTLOAD
  1. S DOLLARJ=""
  1. 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)
  1. D CHKQUED
  1. Q
  1. ;
  1. STARTHL7 ;start HL7 system, but first do some cleanup
  1. ;
  1. D RECOUNT()
  1. ;
  1. ;set the system status flag to active
  1. S $P(^HLD(779.1,1,0),"^",9)=1
  1. ;
  1. ;don't start a process manager if already running
  1. L +^HLTMP("PROCESS MANAGER"):1
  1. Q:'$T
  1. ;
  1. ;start the HL7 Process Manager, which will start everything else
  1. N PROCESS
  1. S PROCESS("NAME")="PROCESS MANAGER"
  1. S PROCESS("IEN")=$O(^HLD(779.3,"B","PROCESS MANAGER",0))
  1. D DOWORK(.PROCESS)
  1. L -^HLTMP("PROCESS MANAGER")
  1. Q
  1. ;
  1. QUIT1(COUNT) ;just returns 1 as function value first time around,then 0, insuring that the DO WORK function is called just once
  1. I '$G(COUNT) S COUNT=1 Q 1
  1. Q 0
  1. ;
  1. CHKDEAD(WORK) ;
  1. ;did any process terminate without erasing itself?
  1. ;WORK (pass by reference, not required) by the Process Manager that is not used and not required
  1. N DOLLARJ S DOLLARJ=""
  1. L +HL7("COUNTING PROCESSES"):20
  1. Q:'$T
  1. F S DOLLARJ=$O(^HLTMP("HL7 RUNNING PROCESSES",DOLLARJ)) Q:DOLLARJ="" I DOLLARJ'=$J L +^HLTMP("HL7 RUNNING PROCESSES",DOLLARJ):0 D:$T
  1. .L -^HLTMP("HL7 RUNNING PROCESSES",DOLLARJ)
  1. .N PROC
  1. .S PROC=$P($G(^HLTMP("HL7 RUNNING PROCESSES",DOLLARJ)),"^",3)
  1. .K ^HLTMP("HL7 RUNNING PROCESSES",DOLLARJ)
  1. .Q:PROC=""
  1. .I $$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","RUNNING",PROC)),-1)<0,$$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","RUNNING",PROC)),1)
  1. L -HL7("COUNTING PROCESSES")
  1. Q
  1. CHKQUED ;did any queued task get dequeued without being erased?
  1. N PROC,JOB
  1. L +HL7("COUNTING PROCESSES"):20
  1. Q:'$T
  1. S JOB=""
  1. F S JOB=$O(^HLTMP("HL7 QUEUED PROCESSES",JOB)) Q:JOB="" I '$$QUEUED(JOB) D
  1. .N PROC
  1. .S PROC=$P($G(^HLTMP("HL7 QUEUED PROCESSES",JOB)),"^",2)
  1. .I PROC]"",$$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","QUEUED",PROC)),-1)<0,$$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","QUEUED",PROC)),1)
  1. .K ^HLTMP("HL7 QUEUED PROCESSES",JOB)
  1. L -HL7("COUNTING PROCESSES")
  1. Q
  1. ;
  1. QUEUED(TASK) ;
  1. ;function returns 0 if ZTSK is not queued to run, 1 if it is
  1. N ZTSK
  1. S ZTSK=TASK
  1. D ISQED^%ZTLOAD
  1. Q:ZTSK(0) 1
  1. Q 0
  1. ;
  1. CNTLIVE ;count the running processes
  1. N JOB,COUNTS,PROC
  1. L +HL7("COUNTING PROCESSES"):20
  1. Q:'$T
  1. S JOB=""
  1. 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
  1. S PROC="" F S PROC=$O(COUNTS(PROC)) Q:PROC="" S ^HLC("HL7 PROCESS COUNTS","RUNNING",PROC)=COUNTS(PROC)
  1. S PROC="" F S PROC=$O(^HLC("HL7 PROCESS COUNTS","RUNNING",PROC)) Q:PROC="" S ^HLC("HL7 PROCESS COUNTS","RUNNING",PROC)=+$G(COUNTS(PROC))
  1. L -HL7("COUNTING PROCESSES")
  1. Q
  1. ;
  1. CNTQUED ;count the queued tasks
  1. N JOB,COUNTS,PROC
  1. L +HL7("COUNTING PROCESSES"):20
  1. Q:'$T
  1. S JOB=""
  1. 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
  1. S PROC="" F S PROC=$O(COUNTS(PROC)) Q:PROC="" S ^HLC("HL7 PROCESS COUNTS","QUEUED",PROC)=COUNTS(PROC)
  1. S PROC="" F S PROC=$O(^HLC("HL7 PROCESS COUNTS","QUEUED",PROC)) Q:PROC="" S ^HLC("HL7 PROCESS COUNTS","QUEUED",PROC)=+$G(COUNTS(PROC))
  1. L -HL7("COUNTING PROCESSES")
  1. Q
  1. ;
  1. RECOUNT(RECOUNT) ;check that the processes that are supposed to be running actually are, same for the queued processes
  1. ;Input:
  1. ; RECOUNT (pass by reference, optional) not used, but passed in by the process manager
  1. ;
  1. ;
  1. ;check for processes that are supposed to be running or queued but aren't
  1. D CHKDEAD(),CHKQUED
  1. ;
  1. ;recount the processes
  1. D CNTLIVE,CNTQUED
  1. Q