- %ZTLOAD ;ISF/RDS,RWF - TaskMan: Programmer Interface: Entry Points ;07/26/2006
- ;;8.0;KERNEL;**67,118,127,339,381**;JUL 10, 1995;Build 2
- ;
- QUEUE ;queue a task (create, schedule) (Entry Point = ^%ZTLOAD)
- G ^%ZTLOAD1
- ;
- S(MSG) ;Entry Point: extrinsic variable returns boolean: should task stop?
- I $G(ZTQUEUED)>.5,$D(^%ZTSCH("TASK",ZTQUEUED)) S ^%ZTSCH("TASK",ZTQUEUED,1)=$H
- I $D(MSG),$G(ZTQUEUED)>.5 S ^%ZTSK(ZTQUEUED,.11)=MSG
- N ZTSTOP S ZTSTOP=0
- I $G(ZTQUEUED)>.5,$L($P($G(^%ZTSK(ZTQUEUED,.1)),"^",10)) S ZTSTOP=1
- Q ZTSTOP
- ;
- TM() ;Entry Point: extrinsic variable returns boolean: is TM running?
- N ZTH,ZTR S ZTH=$H,ZTR=$G(^%ZTSCH("RUN"))
- Q ZTH-ZTR*86400+$P(ZTH,",",2)-$P(ZTR,",",2)<500
- ;
- REQ ;Entry Point: requeue a task (edit, reschedule)
- G ^%ZTLOAD3
- ;
- KILL ;Entry Point: delete a task
- S ZTSK=$G(ZTSK)
- K ZTSK(0) S ZTSK(0)=0
- I ZTSK>1,$D(^%ZTSK(ZTSK)) D L -^%ZTSK(ZTSK) ;could be done!
- . L +^%ZTSK(ZTSK):20 Q:'$T
- . ;Don't kill running persistent tasks.
- . I $D(^%ZTSCH("ZTSK",ZTSK,"P")) Q
- . K ^%ZTSK(ZTSK) S ZTSK(0)=1
- Q
- ;
- ISQED ;Entry Point: return whether task is pending (scheduled or waiting)
- G ^%ZTLOAD4
- ;
- STAT ;Entry Point: return status of a task
- G ^%ZTLOAD5
- ;
- DQ ;Entry Point: dequeue a task (unschedule)
- G ^%ZTLOAD6
- ;
- DESC(DESC,LST) ;Find tasks with description
- G DESC^%ZTLOAD5
- ;
- RTN(RTN,LST) ;Find tasks that call this routine
- G RTN^%ZTLOAD5
- ;
- OPTION(OPNM,LST) ;Find tasks for this OPTION.
- G OPTION^%ZTLOAD5
- ;
- JOB(ZTM) ;Return the job # for a running task
- G JOB^%ZTLOAD5
- ;
- ZTSAVE(%,%1) ;input variables in string delimited by ; to build ZTSAVE array
- N %2 K:$G(%1) ZTSAVE
- F %1=1:1 S %2=$P(%,";",%1) Q:%2="" S ZTSAVE(%2)=""
- Q
- ;
- PSET(ZTM) ;e.f. Set the persistents node
- D TN Q:'$D(^%ZTSCH("TASK",ZTM)) 0
- S ^%ZTSCH("TASK",ZTM,"P")=""
- Q 1
- ;
- PCLEAR(ZTM) ;Clear the persistents node
- D TN Q:'$D(^%ZTSCH("TASK",ZTM))
- K ^%ZTSCH("TASK",ZTM,"P")
- Q
- ;
- ASKSTOP(ZTSK) ;E.F. Ask a task to stop.
- G ASKSTOP^%ZTLOAD2
- Q
- ;
- TN S ZTM=$S($G(ZTM)>0:ZTM,$G(ZTQUEUED)>.9:ZTQUEUED,$G(ZTSK)>0:ZTSK,1:0)
- Q
- --- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HZTLOAD 2106 printed Jan 18, 2025@03:17:08 Page 2
- %ZTLOAD ;ISF/RDS,RWF - TaskMan: Programmer Interface: Entry Points ;07/26/2006
- +1 ;;8.0;KERNEL;**67,118,127,339,381**;JUL 10, 1995;Build 2
- +2 ;
- QUEUE ;queue a task (create, schedule) (Entry Point = ^%ZTLOAD)
- +1 GOTO ^%ZTLOAD1
- +2 ;
- S(MSG) ;Entry Point: extrinsic variable returns boolean: should task stop?
- +1 IF $GET(ZTQUEUED)>.5
- IF $DATA(^%ZTSCH("TASK",ZTQUEUED))
- SET ^%ZTSCH("TASK",ZTQUEUED,1)=$HOROLOG
- +2 IF $DATA(MSG)
- IF $GET(ZTQUEUED)>.5
- SET ^%ZTSK(ZTQUEUED,.11)=MSG
- +3 NEW ZTSTOP
- SET ZTSTOP=0
- +4 IF $GET(ZTQUEUED)>.5
- IF $LENGTH($PIECE($GET(^%ZTSK(ZTQUEUED,.1)),"^",10))
- SET ZTSTOP=1
- +5 QUIT ZTSTOP
- +6 ;
- TM() ;Entry Point: extrinsic variable returns boolean: is TM running?
- +1 NEW ZTH,ZTR
- SET ZTH=$HOROLOG
- SET ZTR=$GET(^%ZTSCH("RUN"))
- +2 QUIT ZTH-ZTR*86400+$PIECE(ZTH,",",2)-$PIECE(ZTR,",",2)<500
- +3 ;
- REQ ;Entry Point: requeue a task (edit, reschedule)
- +1 GOTO ^%ZTLOAD3
- +2 ;
- KILL ;Entry Point: delete a task
- +1 SET ZTSK=$GET(ZTSK)
- +2 KILL ZTSK(0)
- SET ZTSK(0)=0
- +3 ;could be done!
- IF ZTSK>1
- IF $DATA(^%ZTSK(ZTSK))
- Begin DoDot:1
- +4 LOCK +^%ZTSK(ZTSK):20
- if '$TEST
- QUIT
- +5 ;Don't kill running persistent tasks.
- +6 IF $DATA(^%ZTSCH("ZTSK",ZTSK,"P"))
- QUIT
- +7 KILL ^%ZTSK(ZTSK)
- SET ZTSK(0)=1
- End DoDot:1
- LOCK -^%ZTSK(ZTSK)
- +8 QUIT
- +9 ;
- ISQED ;Entry Point: return whether task is pending (scheduled or waiting)
- +1 GOTO ^%ZTLOAD4
- +2 ;
- STAT ;Entry Point: return status of a task
- +1 GOTO ^%ZTLOAD5
- +2 ;
- DQ ;Entry Point: dequeue a task (unschedule)
- +1 GOTO ^%ZTLOAD6
- +2 ;
- DESC(DESC,LST) ;Find tasks with description
- +1 GOTO DESC^%ZTLOAD5
- +2 ;
- RTN(RTN,LST) ;Find tasks that call this routine
- +1 GOTO RTN^%ZTLOAD5
- +2 ;
- OPTION(OPNM,LST) ;Find tasks for this OPTION.
- +1 GOTO OPTION^%ZTLOAD5
- +2 ;
- JOB(ZTM) ;Return the job # for a running task
- +1 GOTO JOB^%ZTLOAD5
- +2 ;
- ZTSAVE(%,%1) ;input variables in string delimited by ; to build ZTSAVE array
- +1 NEW %2
- if $GET(%1)
- KILL ZTSAVE
- +2 FOR %1=1:1
- SET %2=$PIECE(%,";",%1)
- if %2=""
- QUIT
- SET ZTSAVE(%2)=""
- +3 QUIT
- +4 ;
- PSET(ZTM) ;e.f. Set the persistents node
- +1 DO TN
- if '$DATA(^%ZTSCH("TASK",ZTM))
- QUIT 0
- +2 SET ^%ZTSCH("TASK",ZTM,"P")=""
- +3 QUIT 1
- +4 ;
- PCLEAR(ZTM) ;Clear the persistents node
- +1 DO TN
- if '$DATA(^%ZTSCH("TASK",ZTM))
- QUIT
- +2 KILL ^%ZTSCH("TASK",ZTM,"P")
- +3 QUIT
- +4 ;
- ASKSTOP(ZTSK) ;E.F. Ask a task to stop.
- +1 GOTO ASKSTOP^%ZTLOAD2
- +2 QUIT
- +3 ;
- TN SET ZTM=$SELECT($GET(ZTM)>0:ZTM,$GET(ZTQUEUED)>.9:ZTQUEUED,$GET(ZTSK)>0:ZTSK,1:0)
- +1 QUIT