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

XMKPR.m

Go to the documentation of this file.
  1. XMKPR ;ISC-SF/GMB-Post, remote ;10/09/2002 09:40
  1. ;;8.0;MailMan;**5,6**;Jun 28, 2002
  1. ; Replaces ^XMBPOST and the first part of ^XMS1 (ISC-WASH/THM/RWF/CAP)
  1. ; Schedule a task to deliver remote
  1. REMOTE(XMZ,XMINST) ; For addresses containing "@"
  1. N XMSITE,XMREC,XMPOLL
  1. S XMREC=^DIC(4.2,XMINST,0)
  1. S XMSITE=$P(XMREC,U)
  1. D PUTMSG^XMXMSGS2(.5,XMINST+1000,XMSITE,XMZ)
  1. Q:$P(XMREC,U,2)'["S" ; S means to start task immediately
  1. D:'$$TSKEXIST(XMINST) QUEUE(XMINST,XMSITE)
  1. Q
  1. TSKEXIST(XMINST,XMTSK) ;Is Task scheduled ? (0=no,ZTSK^$H=pending,ZTSK=running)
  1. ; Note: ZTSK does not exist when 'playing a script', or for an incoming
  1. ; transmission.
  1. S:'$G(XMTSK) XMTSK=$$GETTSK(XMINST)
  1. Q:'XMTSK 0
  1. I $D(ZTQUEUED),$G(ZTSK)=XMTSK Q ZTSK
  1. N ZTSK
  1. S ZTSK=XMTSK
  1. D STAT^%ZTLOAD
  1. Q:ZTSK(1)=0 0 ; "Undefined"
  1. I ZTSK(1)=1 D Q ZTSK_U_ZTSK("D") ; "Active: Pending"
  1. . D ISQED^%ZTLOAD ; ZTSK("D")=$H when scheduled
  1. I ZTSK(1)=2 Q ZTSK ; "Active: Running"
  1. ;I ZTSK(1)=2 N %1 D L -^DIC(4.2,+$G(XMINST),"XMNETSEND") Q %1
  1. ;. ; "Active: Running" - This check isn't reliable,
  1. ;. ; because the lock is not set for incoming, only for outgoing.
  1. ;. L +^DIC(4.2,+$G(XMINST),"XMNETSEND"):2 ; Is it really running?
  1. ;. I $T D KILLTSK(XMINST,ZTSK) S %1=0 Q ; Nope
  1. ;. S %1=ZTSK ; Yep
  1. Q:ZTSK(1)=3 0 ; "Inactive: Finished"
  1. I ZTSK(1)=4 D KILLTSK(XMINST,ZTSK) Q 0 ; "Inactive: Available"
  1. I ZTSK(1)=5 D KILLTSK(XMINST,ZTSK) Q 0 ; "Interrupted"
  1. Q
  1. GETTSK(XMINST) ;
  1. L +^XMBS(4.2999,XMINST,3):0 L -^XMBS(4.2999,XMINST,3) ; ensure latest
  1. Q $P($G(^XMBS(4.2999,XMINST,3)),U,7)
  1. KILLTSK(XMINST,ZTSK) ;
  1. D KILL^%ZTLOAD
  1. S $P(^XMBS(4.2999,XMINST,3),U,7)=""
  1. S $P(^XMBS(4.2999,XMINST,4),U,2)=$$NOW^XLFDT
  1. Q
  1. QUEUE(XMINST,XMSITE,XMB,ZTDTH,ZTSK) ;
  1. ; Was ENQ^XMS1 used by ^XMC2,^XMS5,^XMS5B ***
  1. ; in:
  1. ; XMINST domain IEN in domain file
  1. ; XMSITE domain name
  1. ; XMB (optional) script choice (default: highest priority script)
  1. ; ZTDTH (optional) task start time (default: now)
  1. ; out:
  1. ; ZTSK task number
  1. N I,XMIENS,XMFDA,ZTIO,ZTDESC,ZTRTN
  1. I '$D(^XMBS(4.2999,XMINST,0)) D STAT^XMTDR(XMINST)
  1. L +^XMBS(4.2999,XMINST):1
  1. I '$G(XMB("SCR IEN")) D Q:'XMB("SCR IEN")
  1. . D XMTCHECK(XMINST,.XMB)
  1. . D SCRIPT^XMKPR1(XMINST,XMSITE,.XMB)
  1. S ZTIO=$P(XMB("SCR REC"),U,5)
  1. S ZTDESC=$$EZBLD^DIALOG(42000,XMSITE) ; MailMan: To |1|
  1. S:'$G(ZTDTH) ZTDTH=$H
  1. F I="XMINST","XMPOLL" S ZTSAVE(I)=""
  1. S ZTRTN="TASK^XMTDR"
  1. D ^%ZTLOAD
  1. S ^XMBS(4.2999,XMINST,3)="" ; current xmit stats
  1. S $P(^XMBS(4.2999,XMINST,3),U,7)=ZTSK
  1. S XMIENS=XMINST_","
  1. I 'XMB("TRIES"),'XMB("ITERATIONS") D
  1. . S XMFDA(4.2999,XMIENS,41)="@" ; xmit start date/time
  1. . S XMFDA(4.2999,XMIENS,42)="@" ; xmit finish date/time
  1. . S XMFDA(4.2999,XMIENS,45)="@" ; xmit latest try date/time
  1. . K ^XMBS(4.2999,XMINST,6) ; xmit audit multiple
  1. S XMFDA(4.2999,XMIENS,25)=ZTSK ; task number
  1. S XMFDA(4.2999,XMIENS,43)=XMB("SCR IEN") ; ien of script to be used
  1. S XMFDA(4.2999,XMIENS,44)=XMB("TRIES") ; xmit tries
  1. S XMFDA(4.2999,XMIENS,46)=XMB("ITERATIONS") ; xmit iterations
  1. S XMFDA(4.2999,XMIENS,47)=XMB("FIRST SCRIPT") ; ien of first script
  1. S XMFDA(4.2999,XMIENS,48)=XMB("IP TRIED") ; IP addresses tried
  1. S XMFDA(4.2999,XMIENS,51)=XMB("SCR REC") ; script record
  1. D FILE^DIE("","XMFDA")
  1. L -^XMBS(4.2999,XMINST)
  1. Q
  1. XMTCHECK(XMINST,XMB) ;
  1. N XMTREC
  1. L +^XMBS(4.2999,XMINST,4):0 L -^XMBS(4.2999,XMINST,4) ; ensure latest
  1. S XMTREC=$G(^XMBS(4.2999,XMINST,4))
  1. Q:'$P(XMTREC,U,1)!$P(XMTREC,U,2)
  1. ; Start time, but no finish time.
  1. ; Previous transmission attempt was aborted. Pick up where we left off.
  1. S XMB("SCR IEN")=$P(XMTREC,U,3)
  1. S XMB("TRIES")=$P(XMTREC,U,4)
  1. S XMB("LAST TRY")=$P(XMTREC,U,5)
  1. S XMB("ITERATIONS")=$P(XMTREC,U,6)
  1. S XMB("FIRST SCRIPT")=$P(XMTREC,U,7)
  1. S XMB("IP TRIED")=$P(XMTREC,U,8)
  1. S XMB("SCR REC")=$G(^XMBS(4.2999,XMINST,5))
  1. Q
  1. REQUEUE(XMINST,XMSITE,XMB) ;
  1. N XMFDA,XMIENS,ZTDTH,ZTIO,ZTDESC,ZTRTN
  1. S XMFDA(4.29992,XMB("AUDIT IENS"),2)=$E($G(ER("MSG"),$$EZBLD^DIALOG(42192)),1,200) ;Unknown Error
  1. D FILE^DIE("","XMFDA")
  1. I XMB("TRIES")+1=$P(XMB("SCR REC"),U,3) D POSTFAIL(XMINST,XMSITE,.XMB)
  1. D SCRIPT^XMKPR1(XMINST,XMSITE,.XMB) Q:'XMB("SCR IEN")
  1. S XMIENS=XMINST_","
  1. S XMFDA(4.2999,XMIENS,43)=XMB("SCR IEN") ; ien of script to be used
  1. S XMFDA(4.2999,XMIENS,44)=XMB("TRIES") ; xmit tries
  1. S XMFDA(4.2999,XMIENS,46)=XMB("ITERATIONS") ; xmit iterations
  1. S XMFDA(4.2999,XMIENS,48)=XMB("IP TRIED") ; IP addresses tried
  1. S XMFDA(4.2999,XMIENS,51)=XMB("SCR REC") ; script record
  1. D FILE^DIE("","XMFDA")
  1. ; XMB("TRIES") starts off at 0 with every script.
  1. ; Each time the script is retried, XMB("TRIES") is bumped up by 1.
  1. ; XMB("ITERATIONS") starts off at 0. After a cycle of scripts is tried,
  1. ; XMB("ITERATIONS") is bumped up by 1 when the cycle is started again.
  1. ; We start every new cycle after one hour.
  1. ; We start every new try after one minute
  1. I XMB("TRIES") D
  1. . S ZTDTH=$$HADD^XLFDT($H,"","",1) ; New try, add 1 minute
  1. E I XMB("ITERATIONS"),XMB("SCR IEN")=XMB("FIRST SCRIPT") D
  1. . S ZTDTH=$$HADD^XLFDT($H,"",1) ; New iteration, add 1 hour
  1. E S ZTDTH=$H ; First try, new script within same iteration
  1. S ZTIO=$P(XMB("SCR REC"),U,5)
  1. S ZTDESC=$$EZBLD^DIALOG(42000.1,XMSITE) ;MailMan: To |1| (requeue)
  1. ; ("_XMB("ITERATIONS")_","_XMB("SCR IEN")_","_XMB("TRIES")_")"
  1. S ZTRTN="TASK^XMTDR"
  1. S ZTREQ=ZTDTH_U_ZTIO_U_ZTDESC_U_ZTRTN
  1. D DOTRAN^XMC1(42000.2,XMSITE) ;|1| Requeued
  1. Q
  1. POSTFAIL(XMINST,XMSITE,XMB) ; Postmaster message on queue failure
  1. N XMPARM,XMINSTR,XMI,XMJ,XMTRIES,XMFIRST
  1. K ^TMP("XM",$J)
  1. S XMINSTR("FROM")="POSTMASTER",XMINSTR("ADDR FLAGS")="R"
  1. S XMTRIES=$P(XMB("SCR REC"),U,3)
  1. S XMPARM(1)=XMSITE,XMPARM(2)=XMTRIES
  1. S XMJ=0
  1. S XMJ=XMJ+1,^TMP("XM",$J,XMJ,0)=""
  1. S XMFIRST=$P($G(^XMBS(4.2999,XMINST,6,0)),U,3)-XMTRIES
  1. S:XMFIRST<0 XMFIRST=0
  1. S XMI=XMFIRST ; Get tries audit from ^XMBS(4.2999, "XMIT AUDIT" multiple
  1. F S XMI=$O(^XMBS(4.2999,XMINST,6,XMI)) Q:'XMI S XMJ=XMJ+1,^TMP("XM",$J,XMJ,0)=^(XMI,0)
  1. S XMJ=XMJ+1,^TMP("XM",$J,XMJ,0)=""
  1. S XMJ=XMJ+1,^TMP("XM",$J,XMJ,0)=$$EZBLD^DIALOG(42190) ;A transcript of the last delivery attempt follows:
  1. S XMJ=XMJ+1,^TMP("XM",$J,XMJ,0)=""
  1. S XMI=0
  1. F S XMI=$O(^TMP("XMC",XMC("AUDIT"),XMI)) Q:'XMI S XMJ=XMJ+1,^TMP("XM",$J,XMJ,0)=^(XMI,0)
  1. I XMFIRST'=0 D
  1. . N XMMAX ; Maximum number of old audit records
  1. . S XMMAX=100
  1. . S XMJ=XMJ+1,^TMP("XM",$J,XMJ,0)="**********************************************"
  1. . S XMJ=XMJ+1,^TMP("XM",$J,XMJ,0)=""
  1. . I XMFIRST'>XMMAX D
  1. . . S XMI=0
  1. . . S XMJ=XMJ+1,^TMP("XM",$J,XMJ,0)=$$EZBLD^DIALOG(42191) ;The following errors occurred in previous attempts:
  1. . E D
  1. . . S XMI=XMFIRST-XMMAX
  1. . . S XMJ=XMJ+1,^TMP("XM",$J,XMJ,0)=$$EZBLD^DIALOG(42191.1,$$FMTE^XLFDT($P(^XMBS(4.2999,XMINST,6,1,0),U,1),5)) ;The errors started on |1|.
  1. . . S XMJ=XMJ+1,^TMP("XM",$J,XMJ,0)=""
  1. . . S XMJ=XMJ+1,^TMP("XM",$J,XMJ,0)=$$EZBLD^DIALOG(42191.2,XMMAX) ;The following errors occurred in the previous |1| attempts:
  1. . ; Get tries audit from ^XMBS(4.2999, "XMIT AUDIT" multiple
  1. . S XMJ=XMJ+1,^TMP("XM",$J,XMJ,0)=""
  1. . F S XMI=$O(^XMBS(4.2999,XMINST,6,XMI)) Q:XMI>XMFIRST S XMJ=XMJ+1,^TMP("XM",$J,XMJ,0)=^(XMI,0)
  1. D TASKBULL^XMXBULL(.5,"XM SEND ERR TRANSMISSION",.XMPARM,"^TMP(""XM"",$J)",.5,.XMINSTR)
  1. K ^TMP("XM",$J)
  1. Q