VDEFMON ;BPOIFO/JG - VDEF Queue Process Monitor ; 20 Dec 2005 13:00 PM
;;1.0;VDEF;**3**;Dec 28, 2004
;Per VHA Directive 2004-038, this routine should not be modified.
;
Q ; No bozos
;
START ; Main entry point for scheduling queue processor monitor in TaskMan
I '$D(ZTQUEUED) W !,"Must be run from TaskMan." Q
;
START1 ; Non-TaskMan entry
;
; Only one of these needs to be running.
L +^VDEFHL7("REQMON"):1 Q:'$T
;
; Start the Request Queue processor monitor
N ZTDESC,ZTDTH,ZTIO,ZTPRI,ZTRTN,ZTSK
S ZTRTN="MONITOR^VDEFMON",(ZTIO,ZTPRI)="",ZTDTH=$H
S ZTDESC="VDEF Request Processor Monitor"
L -^VDEFHL7("REQMON")
D ^%ZTLOAD
;
; Check that TaskMan successfully queued up the Monitor task
I '$G(ZTSK) D ALERT^VDEFUTIL("VDEF QUEUE PROCESS MONITOR DID NOT START. CHECK ERROR TRAP.")
Q
;
; Main entry point for the Request Queue process monitor from TaskMan.
; Check the Request Queue processor for each queue that is defined
; and has a status of "R" (running). If it is not running, send an alert
; and restart it.
; If the Request Queue is currently suspended, send an alert telling
; site to restart it.
MONITOR L +^VDEFHL7("REQMON"):1 Q:'$T
N QIEN,QUEFAIL,QUESTOP,VDEFTSK S VDEFTSK=ZTSK
MONITOR1 S QIEN=0
F S QIEN=+$O(^VDEFHL7(579.3,QIEN)) Q:'QIEN D D ALERTSUS:QUESTOP,ALERT:QUEFAIL
. S (QUESTOP,QUEFAIL)=0
. S QUESTOP=$P(^VDEFHL7(579.3,QIEN,0),U,9)="S" Q:QUESTOP
. ;
. ; Try to lock this Request Queue. If it's already locked,
. ; assume that the Request queue processor is running OK.
. L +^VDEFHL7(579.3,"QUEUE",QIEN):1 S QUEFAIL=$T
. L -^VDEFHL7(579.3,"QUEUE",QIEN)
;
; Requeue any requests that are stuck in Checked Out or Errored Out status.
S QIEN=0 N RQ
F S QIEN=+$O(^VDEFHL7(579.3,QIEN)) Q:'QIEN D
. I +$O(^VDEFHL7(579.3,"C","C",QIEN,"")) D
.. D REQUEUE^VDEFQM(QIEN,.RQ)
.. D:RQ ALERT^VDEFUTIL("VDEF HAS REQUEUED CHECKED OUT RECORDS. NO ACTION NEEDED.")
. I +$O(^VDEFHL7(579.3,"C","E",QIEN,"")) D
.. D RQERR^VDEFQM(QIEN,.RQ)
.. D:RQ ALERT^VDEFUTIL("VDEF HAS REQUEUED ERRORED OUT RECORDS. NO ACTION NEEDED.")
;
; Wait for 10 minutes before checking the queue processors again.
; The wait process is in a loop so it can check if there
; has been a request to stop processing before the wait expires.
WAITLOOP N I F I=1:1:600 D Q:ZTSTOP
. S ZTSTOP=$$S^%ZTLOAD() Q:ZTSTOP
. H 1
;
; Quit or resume processing
G MONITOR1:'$G(ZTSTOP)
;
; Send an alert and delete this task's record
EXIT D ALERT^VDEFUTIL("VDEF QUEUE PROCESS MONITOR HAS EXITED.")
L -^VDEFHL7("REQMON")
S ZTSK=VDEFTSK,ZTSTOP=1,ZTREQ="@"
Q
;
; Generate the failure/restart alert
ALERT N QUEUE,Y D ALERTDAT
D ALERT^VDEFUTIL("VDEF QUEUE '"_QUEUE_"' AUTO-RESTARTED. NO ACTION REQUIRED.")
;
; Restart the Request Queue processor
D REQ^VDEFCONT(QIEN)
Q
;
; Generate the alert that a Request Queue is suspended.
ALERTSUS N QUEUE,Y D ALERTDAT
D ALERT^VDEFUTIL("VDEF QUEUE '"_QUEUE_"' IS SUSPENDED. PLEASE START IT.")
Q
;
; Get the queue name
ALERTDAT S QUEUE=$P(^VDEFHL7(579.3,QIEN,0),U)
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HVDEFMON 3113 printed Oct 16, 2024@18:44:28 Page 2
VDEFMON ;BPOIFO/JG - VDEF Queue Process Monitor ; 20 Dec 2005 13:00 PM
+1 ;;1.0;VDEF;**3**;Dec 28, 2004
+2 ;Per VHA Directive 2004-038, this routine should not be modified.
+3 ;
+4 ; No bozos
QUIT
+5 ;
START ; Main entry point for scheduling queue processor monitor in TaskMan
+1 IF '$DATA(ZTQUEUED)
WRITE !,"Must be run from TaskMan."
QUIT
+2 ;
START1 ; Non-TaskMan entry
+1 ;
+2 ; Only one of these needs to be running.
+3 LOCK +^VDEFHL7("REQMON"):1
if '$TEST
QUIT
+4 ;
+5 ; Start the Request Queue processor monitor
+6 NEW ZTDESC,ZTDTH,ZTIO,ZTPRI,ZTRTN,ZTSK
+7 SET ZTRTN="MONITOR^VDEFMON"
SET (ZTIO,ZTPRI)=""
SET ZTDTH=$HOROLOG
+8 SET ZTDESC="VDEF Request Processor Monitor"
+9 LOCK -^VDEFHL7("REQMON")
+10 DO ^%ZTLOAD
+11 ;
+12 ; Check that TaskMan successfully queued up the Monitor task
+13 IF '$GET(ZTSK)
DO ALERT^VDEFUTIL("VDEF QUEUE PROCESS MONITOR DID NOT START. CHECK ERROR TRAP.")
+14 QUIT
+15 ;
+16 ; Main entry point for the Request Queue process monitor from TaskMan.
+17 ; Check the Request Queue processor for each queue that is defined
+18 ; and has a status of "R" (running). If it is not running, send an alert
+19 ; and restart it.
+20 ; If the Request Queue is currently suspended, send an alert telling
+21 ; site to restart it.
MONITOR LOCK +^VDEFHL7("REQMON"):1
if '$TEST
QUIT
+1 NEW QIEN,QUEFAIL,QUESTOP,VDEFTSK
SET VDEFTSK=ZTSK
MONITOR1 SET QIEN=0
+1 FOR
SET QIEN=+$ORDER(^VDEFHL7(579.3,QIEN))
if 'QIEN
QUIT
Begin DoDot:1
+2 SET (QUESTOP,QUEFAIL)=0
+3 SET QUESTOP=$PIECE(^VDEFHL7(579.3,QIEN,0),U,9)="S"
if QUESTOP
QUIT
+4 ;
+5 ; Try to lock this Request Queue. If it's already locked,
+6 ; assume that the Request queue processor is running OK.
+7 LOCK +^VDEFHL7(579.3,"QUEUE",QIEN):1
SET QUEFAIL=$TEST
+8 LOCK -^VDEFHL7(579.3,"QUEUE",QIEN)
End DoDot:1
if QUESTOP
DO ALERTSUS
if QUEFAIL
DO ALERT
+9 ;
+10 ; Requeue any requests that are stuck in Checked Out or Errored Out status.
+11 SET QIEN=0
NEW RQ
+12 FOR
SET QIEN=+$ORDER(^VDEFHL7(579.3,QIEN))
if 'QIEN
QUIT
Begin DoDot:1
+13 IF +$ORDER(^VDEFHL7(579.3,"C","C",QIEN,""))
Begin DoDot:2
+14 DO REQUEUE^VDEFQM(QIEN,.RQ)
+15 if RQ
DO ALERT^VDEFUTIL("VDEF HAS REQUEUED CHECKED OUT RECORDS. NO ACTION NEEDED.")
End DoDot:2
+16 IF +$ORDER(^VDEFHL7(579.3,"C","E",QIEN,""))
Begin DoDot:2
+17 DO RQERR^VDEFQM(QIEN,.RQ)
+18 if RQ
DO ALERT^VDEFUTIL("VDEF HAS REQUEUED ERRORED OUT RECORDS. NO ACTION NEEDED.")
End DoDot:2
End DoDot:1
+19 ;
+20 ; Wait for 10 minutes before checking the queue processors again.
+21 ; The wait process is in a loop so it can check if there
+22 ; has been a request to stop processing before the wait expires.
WAITLOOP NEW I
FOR I=1:1:600
Begin DoDot:1
+1 SET ZTSTOP=$$S^%ZTLOAD()
if ZTSTOP
QUIT
+2 HANG 1
End DoDot:1
if ZTSTOP
QUIT
+3 ;
+4 ; Quit or resume processing
+5 if '$GET(ZTSTOP)
GOTO MONITOR1
+6 ;
+7 ; Send an alert and delete this task's record
EXIT DO ALERT^VDEFUTIL("VDEF QUEUE PROCESS MONITOR HAS EXITED.")
+1 LOCK -^VDEFHL7("REQMON")
+2 SET ZTSK=VDEFTSK
SET ZTSTOP=1
SET ZTREQ="@"
+3 QUIT
+4 ;
+5 ; Generate the failure/restart alert
ALERT NEW QUEUE,Y
DO ALERTDAT
+1 DO ALERT^VDEFUTIL("VDEF QUEUE '"_QUEUE_"' AUTO-RESTARTED. NO ACTION REQUIRED.")
+2 ;
+3 ; Restart the Request Queue processor
+4 DO REQ^VDEFCONT(QIEN)
+5 QUIT
+6 ;
+7 ; Generate the alert that a Request Queue is suspended.
ALERTSUS NEW QUEUE,Y
DO ALERTDAT
+1 DO ALERT^VDEFUTIL("VDEF QUEUE '"_QUEUE_"' IS SUSPENDED. PLEASE START IT.")
+2 QUIT
+3 ;
+4 ; Get the queue name
ALERTDAT SET QUEUE=$PIECE(^VDEFHL7(579.3,QIEN,0),U)
+1 QUIT