ORMTIMST ; JM/SLC-ISC - ORMTIME STATUS ROUTINES ;06/06/2006
;;3.0;ORDER ENTRY/RESULTS REPORTING;**253**;Dec 17, 1997
;
EN ; Pre-install environment check - will ORMTIME run in the next 5 minutes?
;
D ENVCHECK(5)
Q
;
RUNNING() ; Checks to see if ORMTIME is running
L +^OR(100,"AE"):2 I $T L -^OR(100,"AE") Q 0
Q 1
;
NEXTRUN() ; Number of minutes before the next scheduled run of ORMTIME. - returns in format MINUTES:SECONDS
; If past scheduled time, but within the last 10 minutes, returns 0 (give TaskMan time to invoke it)
; If -1, unable to determine value
N RESULT,ORY,I,SCHDT,NOWDT,DIFFDT,MAX,DELAY,SEC,MIN,PASTDUE
S MAX=9999999
S RESULT=MAX
S DELAY=10 ; Give Taskman 10 minutes to invoke ORMTIME
S NOWDT=$$NOW^XLFDT
S PASTDUE=$$FMADD^XLFDT(NOWDT,0,0,-DELAY,0)
D OPTSTAT^XUTMOPT("ORMTIME RUN",.ORY) ; get option schedule info IA# 1472
F I=1:1:ORY D Q:(RESULT=0)
. S SCHDT=$P(ORY(I),U,2) ; next scheduled ORMTIME run time
. S DIFFDT=$$FMDIFF^XLFDT(SCHDT,NOWDT,2)
. I DIFFDT<0 D Q
. . I SCHDT>PASTDUE S RESULT=0
. I RESULT>DIFFDT S RESULT=DIFFDT
I RESULT=MAX S RESULT=-1
I RESULT>0 D
. S SEC=RESULT#60,MIN=RESULT\60
. I SEC<10 S SEC="0"_SEC
. S RESULT=MIN_":"_SEC
Q RESULT
;
ENVCHECK(MINUTES) ; Environment check to see if ORMTIME is running, or will run in the next few minutes
;
I '+$G(XPDENV) Q ; Don't evaluate during the global load - just when actually installing
N KIDS
S KIDS=1
G ENVMAIN
;
ENVTEST(MINUTES) ; Run for testing purposes only
N KIDS
S KIDS=0
;
ENVMAIN ;
N I,RUNNING,MSG,CHKSOON,SOON,COUNT,NEXT,STARTMSG
D BOUT("Checking ORMTIME status...")
S RUNNING=$$RUNNING
S CHKSOON=1
S MSG="ORMTIME is "
I RUNNING S MSG=MSG_"running, waiting for it to finish..."
E S MSG=MSG_"not running."
D BOUT(MSG)
I RUNNING D
. S (COUNT,CHKSOON)=0
. F I=1:1:15 D Q:'RUNNING
. . S RUNNING=$$RUNNING
. . I RUNNING S COUNT=COUNT+1 I COUNT>2 S COUNT=0 D OUT(" ORMTIME is still running...")
. I 'RUNNING D
. . H 2 ; Wait 2 seconds after the lock is released, to make sure ORMTIME is finished executing
. . D OUT("ORMTIME is done.")
I RUNNING D ABORT("ORMTIME is taking too long to run.") Q
;
I CHKSOON D Q:SOON
. D BOUT("Checking ORMTIME Schedule...")
. S NEXT=$$NEXTRUN
. S SOON=1
. I (NEXT<0)!(NEXT'<MINUTES) S SOON=0
. S MSG="ORMTIME is "
. I SOON D I 1
. . I NEXT<1 S STARTMSG="less than a minute."
. . E S STARTMSG=NEXT_" minutes."
. E S MSG=MSG_"not " S STARTMSG="the next "_MINUTES_":00 minutes."
. S MSG=MSG_"scheduled to run in "_STARTMSG
. D BOUT(MSG)
. I SOON D ABORT("Too close to ORMTIME's scheduled start time.")
D BOUT("Installation conditions are acceptable, continuing installation...")
Q
;
ABORT(TXT) ; Send abort message
D BOUT("***********************************")
D OUT("***** ABORTING INSTALLATION *****")
D OUT("***********************************")
D OUT(TXT)
D OUT("Try installation again after ORMTIME completes.")
S XPDQUIT=2 ;abort installation but leave transport global in ^XTMP
Q
;
OUT(TEXT) ; Send output - if run from install, send to MES^XPDUTL
I KIDS D MES^XPDUTL(TEXT) I 1
E W TEXT,!
Q
BOUT(TEXT) ; Send output - if run from install, send to BMES^XPDUTL
I KIDS D BMES^XPDUTL(TEXT) I 1
E W !,TEXT,!
Q
PRETEST ; test install
N KIDS
S KIDS=0
G PREMAIN
;
PRECHECK ; Start install - make sure ORMTIME doesn't run while the installation takes place.
N KIDS
S KIDS=1
PREMAIN ;
N COUNT
S COUNT=0
F Q:'$$RUNNING D
. I COUNT=0 D BOUT("ORMTIME is running. Install waiting for ORMTIME to finished...")
. S COUNT=COUNT+1
. I COUNT>4 D OUT(" ORMTIME is still running...") S COUNT=1
I COUNT>0 H 2 D BOUT("ORMTIME has finished running, continuing with install...")
D BOUT("Starting ORMTIME update...")
Q
ORMTIMST ; JM/SLC-ISC - ORMTIME STATUS ROUTINES ;06/06/2006
+1 ;;3.0;ORDER ENTRY/RESULTS REPORTING;**253**;Dec 17, 1997
+2 ;
EN ; Pre-install environment check - will ORMTIME run in the next 5 minutes?
+1 ;
+2 DO ENVCHECK(5)
+3 QUIT
+4 ;
RUNNING() ; Checks to see if ORMTIME is running
+1 LOCK +^OR(100,"AE"):2
IF $TEST
LOCK -^OR(100,"AE")
QUIT 0
+2 QUIT 1
+3 ;
NEXTRUN() ; Number of minutes before the next scheduled run of ORMTIME. - returns in format MINUTES:SECONDS
+1 ; If past scheduled time, but within the last 10 minutes, returns 0 (give TaskMan time to invoke it)
+2 ; If -1, unable to determine value
+3 NEW RESULT,ORY,I,SCHDT,NOWDT,DIFFDT,MAX,DELAY,SEC,MIN,PASTDUE
+4 SET MAX=9999999
+5 SET RESULT=MAX
+6 ; Give Taskman 10 minutes to invoke ORMTIME
SET DELAY=10
+7 SET NOWDT=$$NOW^XLFDT
+8 SET PASTDUE=$$FMADD^XLFDT(NOWDT,0,0,-DELAY,0)
+9 ; get option schedule info IA# 1472
DO OPTSTAT^XUTMOPT("ORMTIME RUN",.ORY)
+10 FOR I=1:1:ORY
Begin DoDot:1
+11 ; next scheduled ORMTIME run time
SET SCHDT=$PIECE(ORY(I),U,2)
+12 SET DIFFDT=$$FMDIFF^XLFDT(SCHDT,NOWDT,2)
+13 IF DIFFDT<0
Begin DoDot:2
+14 IF SCHDT>PASTDUE
SET RESULT=0
End DoDot:2
QUIT
+15 IF RESULT>DIFFDT
SET RESULT=DIFFDT
End DoDot:1
IF (RESULT=0)
QUIT
+16 IF RESULT=MAX
SET RESULT=-1
+17 IF RESULT>0
Begin DoDot:1
+18 SET SEC=RESULT#60
SET MIN=RESULT\60
+19 IF SEC<10
SET SEC="0"_SEC
+20 SET RESULT=MIN_":"_SEC
End DoDot:1
+21 QUIT RESULT
+22 ;
ENVCHECK(MINUTES) ; Environment check to see if ORMTIME is running, or will run in the next few minutes
+1 ;
+2 ; Don't evaluate during the global load - just when actually installing
IF '+$GET(XPDENV)
QUIT
+3 NEW KIDS
+4 SET KIDS=1
+5 GOTO ENVMAIN
+6 ;
ENVTEST(MINUTES) ; Run for testing purposes only
+1 NEW KIDS
+2 SET KIDS=0
+3 ;
ENVMAIN ;
+1 NEW I,RUNNING,MSG,CHKSOON,SOON,COUNT,NEXT,STARTMSG
+2 DO BOUT("Checking ORMTIME status...")
+3 SET RUNNING=$$RUNNING
+4 SET CHKSOON=1
+5 SET MSG="ORMTIME is "
+6 IF RUNNING
SET MSG=MSG_"running, waiting for it to finish..."
+7 IF '$TEST
SET MSG=MSG_"not running."
+8 DO BOUT(MSG)
+9 IF RUNNING
Begin DoDot:1
+10 SET (COUNT,CHKSOON)=0
+11 FOR I=1:1:15
Begin DoDot:2
+12 SET RUNNING=$$RUNNING
+13 IF RUNNING
SET COUNT=COUNT+1
IF COUNT>2
SET COUNT=0
DO OUT(" ORMTIME is still running...")
End DoDot:2
IF 'RUNNING
QUIT
+14 IF 'RUNNING
Begin DoDot:2
+15 ; Wait 2 seconds after the lock is released, to make sure ORMTIME is finished executing
HANG 2
+16 DO OUT("ORMTIME is done.")
End DoDot:2
End DoDot:1
+17 IF RUNNING
DO ABORT("ORMTIME is taking too long to run.")
QUIT
+18 ;
+19 IF CHKSOON
Begin DoDot:1
+20 DO BOUT("Checking ORMTIME Schedule...")
+21 SET NEXT=$$NEXTRUN
+22 SET SOON=1
+23 IF (NEXT<0)!(NEXT'<MINUTES)
SET SOON=0
+24 SET MSG="ORMTIME is "
+25 IF SOON
Begin DoDot:2
+26 IF NEXT<1
SET STARTMSG="less than a minute."
+27 IF '$TEST
SET STARTMSG=NEXT_" minutes."
End DoDot:2
IF 1
+28 IF '$TEST
SET MSG=MSG_"not "
SET STARTMSG="the next "_MINUTES_":00 minutes."
+29 SET MSG=MSG_"scheduled to run in "_STARTMSG
+30 DO BOUT(MSG)
+31 IF SOON
DO ABORT("Too close to ORMTIME's scheduled start time.")
End DoDot:1
IF SOON
QUIT
+32 DO BOUT("Installation conditions are acceptable, continuing installation...")
+33 QUIT
+34 ;
ABORT(TXT) ; Send abort message
+1 DO BOUT("***********************************")
+2 DO OUT("***** ABORTING INSTALLATION *****")
+3 DO OUT("***********************************")
+4 DO OUT(TXT)
+5 DO OUT("Try installation again after ORMTIME completes.")
+6 ;abort installation but leave transport global in ^XTMP
SET XPDQUIT=2
+7 QUIT
+8 ;
OUT(TEXT) ; Send output - if run from install, send to MES^XPDUTL
+1 IF KIDS
DO MES^XPDUTL(TEXT)
IF 1
+2 IF '$TEST
WRITE TEXT,!
+3 QUIT
BOUT(TEXT) ; Send output - if run from install, send to BMES^XPDUTL
+1 IF KIDS
DO BMES^XPDUTL(TEXT)
IF 1
+2 IF '$TEST
WRITE !,TEXT,!
+3 QUIT
PRETEST ; test install
+1 NEW KIDS
+2 SET KIDS=0
+3 GOTO PREMAIN
+4 ;
PRECHECK ; Start install - make sure ORMTIME doesn't run while the installation takes place.
+1 NEW KIDS
+2 SET KIDS=1
PREMAIN ;
+1 NEW COUNT
+2 SET COUNT=0
+3 FOR
IF '$$RUNNING
QUIT
Begin DoDot:1
+4 IF COUNT=0
DO BOUT("ORMTIME is running. Install waiting for ORMTIME to finished...")
+5 SET COUNT=COUNT+1
+6 IF COUNT>4
DO OUT(" ORMTIME is still running...")
SET COUNT=1
End DoDot:1
+7 IF COUNT>0
HANG 2
DO BOUT("ORMTIME has finished running, continuing with install...")
+8 DO BOUT("Starting ORMTIME update...")
+9 QUIT