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'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