KMPTASK ;SP/JML - Cache TaskManager Task ;11/1/2023
;;4.0;CAPACITY MANAGEMENT;**1,4**;3/1/2018;Build 36
;
;
TASK(KMPVNSP) ; CHECK CREATE OR RESUME KMPVRUN TASK IN CACHE TASKMGR
N I,KMPVMSG,KMPVNSPE,KMPVROLS,KMPVSTAT,KMPVTASK,KMPVTFLG,KMPVTSK,KMPVTSKS,KMPX,KMPVTID,KMPVTRUN
;
S KMPVROLS=$ROLES
I (KMPVROLS'["%All")&(KMPVROLS'["%Manager") D Q
.W !,"You must have either the %Manager or the %All Role",!
I $G(KMPVNSP)="" S KMPVNSP=$ZDEFNSP
I '##class(%SYS.Namespace).Exists(KMPVNSP) S KMPVNSP=$ZDEFNSP
S KMPVTSK="KMPVRUN"
I KMPVNSP'=$ZDEFNSP S KMPVTSK=KMPVTSK_"_"_KMPVNSP
S KMPVMSG="CHECKING KMPV SETUP IN "_KMPVNSP_" NAMESPACE..."
W !,KMPVMSG,!!
D ##class(%SYS.System).WriteToConsoleLog("ZSTU: "_KMPVMSG,0,0)
S KMPVTFLG=0
S KMPVTSKS=##class(%ResultSet).%New("%SYS.TaskSuper.TaskListDetail")
S KMPVSTAT=KMPVTSKS.Execute()
F S KMPX=KMPVTSKS.Next() Q:KMPVTSKS.GetDataByName("ID")="" D
.I (KMPVTSKS.GetDataByName("Task Name")=KMPVTSK) D
..S KMPVTID=KMPVTSKS.GetDataByName("ID")
..S KMPVTRUN=KMPVTSKS.GetDataByName("Next Scheduled Date")_" at "_KMPVTSKS.GetDataByName("Next Scheduled Time")
..I KMPVTSKS.GetDataByName("Suspended")'="" D
...D ##class(%SYS.Task).Resume(KMPVTID)
...S KMPVMSG=KMPVTSK_" Task #"_KMPVTID_" Exists and Resumed to Run at "_KMPVTRUN
..E S KMPVMSG=KMPVTSK_" Task #"_KMPVTID_" Exists and Scheduled to Run at "_KMPVTRUN
..S KMPVTFLG=1
..W !,KMPVMSG
..D ##class(%SYS.System).WriteToConsoleLog("ZSTU: "_KMPVMSG,0,0)
;
;create task if it doesn't exist
I 'KMPVTFLG D
.S KMPVTASK=##Class(%SYS.Task).%New()
.S KMPVTASK.Name=KMPVTSK
.S KMPVTASK.Description="Start VSM Collection Drivers"
.S KMPVTASK.NameSpace=KMPVNSP
.S KMPVTASK.TaskClass="%SYS.Task.RunLegacyTask"
.S KMPVTASK.Settings=$lb("ExecuteCode","D RUN^KMPVRUN")
.S KMPVTASK.RunAsUser="_SYSTEM"
.S KMPVTASK.Priority=0
.S KMPVTASK.StartDate=$P($H,",",1)+1
.S KMPVTASK.DailyFrequency=0 ;task.DailyFrequencyDisplayToLogical("Once")
.S KMPVTASK.DailyFrequencyTime=""
.S KMPVTASK.DailyIncrement=""
.S KMPVTASK.DailyStartTime=60
.S KMPVTASK.Expires=0
.S KMPVTASK.DailyEndTime=""
.S KMPVTASK.RescheduleOnStart=1
.S KMPVSTAT=KMPVTASK.%Save()
.I $System.Status.IsError(KMPVSTAT) D Q
..S KMPVMSG(1)="Error #"_$System.Status.GetErrorCodes(KMPVSTAT)
..S KMPVMSG(2)=$System.Status.GetOneStatusText(KMPVSTAT,1)
..S KMPVMSG(3)="Failed to Create and Schedule Task "_KMPVTSK_" in Cache Task Manager"
..F I=1:1:3 W !,KMPVMSG(I) DO ##class(%SYS.System).WriteToConsoleLog("ZSTU: "_KMPVMSG(I),0,1)
.S KMPVMSG="Created and scheduled Task "_KMPVTSK_" in Cache Task Manager"
.W !,KMPVMSG DO ##class(%SYS.System).WriteToConsoleLog("ZSTU: "_KMPVMSG,0,0)
Q
;
ENABLE(KMPNS,KMPABLE) ;
N DA,DIC,DIE,DR,KMPMSG,KMPOPT,KMPOPTS,KMPTIEN,X,Y
D KMPOPTS(KMPNS,.KMPOPTS)
S KMPMSG=$S(KMPABLE=1:"@",1:"Migrated to VSM MANAGEMENT. Contact CPEVSM@DOMAIN.EXT")
S KMPOPT=""
F S KMPOPT=$O(KMPOPTS(KMPOPT)) Q:KMPOPT="" D
.S X=KMPOPT
.S DIC=19,DIC(0)="B"
.D ^DIC
.S KMPTIEN=+Y
.I KMPTIEN>0 D
..S DIE=19,DA=KMPTIEN,DR="2///"_KMPMSG D ^DIE
Q
;
KMPOPTS(KMPNS,KMPOPTS) ;
K KMPOPTS
I KMPNS="KMPS" D
.S KMPOPTS("KMPS SAGG FILE")="",KMPOPTS("KMPS SAGG MANAGER")=""
.S KMPOPTS("KMPS SAGG REPORT")="",KMPOPTS("KMPS SAGG STATUS")=""
.S KMPOPTS("KMPS SAGG STOP")=""
I KMPNS="KMPD" D
.S KMPOPTS("KMPD BACKGROUND DRIVER")="",KMPOPTS("KMPD CM DEVELOPER TOOLS")=""
.S KMPOPTS("KMPD CM TOOLS MANAGER MENU")="",KMPOPTS("KMPD CM TOOLS REPORTS")=""
.;S KMPOPTS("KMPD ECHO")="" - LEAVE OPTION UNTIL REPLACED
.S KMPOPTS("KMPD PARAM EDIT")=""
.S KMPOPTS("KMPD STATUS")="",KMPOPTS("KMPD TMG AVG HR TT")=""
.S KMPOPTS("KMPD TMG AVG TTL")="",KMPOPTS("KMPD TMG DLY TTL DETAIL")=""
.S KMPOPTS("KMPD TMG HRLY TTL")="",KMPOPTS("KMPD TMG HRLY TTL DETAIL")=""
.S KMPOPTS("KMPD TMG HRLY TTL RT")="",KMPOPTS("KMPD TMG MONITOR")=""
.S KMPOPTS("KMPD TMG REPORTS")="",KMPOPTS("KMPD TMG START/STOP")=""
.S KMPOPTS("KMPD TMG TTL ALERT")="",KMPOPTS("KMPD TMG TTL ALERT RT")=""
Q
;
GLOSTATS(KMPDIRS) ;
N B,KMPDIR,KMPRES,KMPSTAT,KMPSTATE,KMPVLN
S KMPVLN=1,B="|"
S KMPSTATE=##class(%SQL.Statement).%New()
S KMPSTAT=KMPSTATE.%PrepareClassQuery("%SYS.GlobalQuery","Size")
S KMPDIR=""
F S KMPDIR=$O(KMPDIRS(KMPDIR)) Q:KMPDIR="" D
.S KMPRES=KMPSTATE.%Execute(KMPDIR,"","*")
.D GLOSET(KMPDIR)
Q
;
GLOSET(KMPDIR) ;
N KMPALL,KMPNAME,KMPUSE
F S KMPX=KMPRES.%Next() Q:KMPRES.%Get("Name")="" D
.S KMPNAME=KMPRES.%Get("Name")
.S KMPALL=KMPRES.%Get("Allocated MB")
.S KMPUSE=KMPRES.%Get("Used MB")
.S ^KMPTMP("KMPV","VSTM","TRANSMIT","GLOBALS",$J,KMPVLN)=KMPDIR_B_KMPNAME_B_KMPALL_B_KMPUSE,KMPVLN=KMPVLN+1
Q
;
ZERO() ;
N B,KMPDATA,KMPFNUM,KMPGNAM,KMPVLN
S U="^",B="|",KMPVLN=1
S KMPFNUM=0 F S KMPFNUM=$O(^DIC(KMPFNUM)) Q:'+KMPFNUM D
.Q:$G(^DIC(KMPFNUM,0))=""
.Q:'$D(^DIC(KMPFNUM,0,"GL"))
.S KMPGNAM=$G(^DIC(KMPFNUM,0,"GL")) Q:KMPGNAM=""
.; file num ^ file name ^ global root ^ version ^ entries ^ last id
.S KMPDATA=KMPFNUM_B_$P(^DIC(KMPFNUM,0),U)_B_KMPGNAM_B_+$G(^DD(+$P(^DIC(KMPFNUM,0),U,2),0,"VR"))_B_+$P($G(@(KMPGNAM_"0)")),U,4)_B_+$P($G(@(KMPGNAM_"0)")),U,3)
.S ^KMPTMP("KMPV","VSTM","TRANSMIT","ZERO",$J,KMPVLN)=KMPDATA,KMPVLN=KMPVLN+1
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HKMPTASK 5267 printed Dec 13, 2024@01:41:55 Page 2
KMPTASK ;SP/JML - Cache TaskManager Task ;11/1/2023
+1 ;;4.0;CAPACITY MANAGEMENT;**1,4**;3/1/2018;Build 36
+2 ;
+3 ;
TASK(KMPVNSP) ; CHECK CREATE OR RESUME KMPVRUN TASK IN CACHE TASKMGR
+1 NEW I,KMPVMSG,KMPVNSPE,KMPVROLS,KMPVSTAT,KMPVTASK,KMPVTFLG,KMPVTSK,KMPVTSKS,KMPX,KMPVTID,KMPVTRUN
+2 ;
+3
*** ERROR ***
SET KMPVROLS=$ROLES
+4 IF (KMPVROLS'["%All")&(KMPVROLS'["%Manager")
Begin DoDot:1
+5 WRITE !,"You must have either the %Manager or the %All Role",!
End DoDot:1
QUIT
+6 IF $GET(KMPVNSP)=""
SET KMPVNSP=$ZDEFNSP
+7 IF '##class(%SYS.Namespace).Exists(KMPVNSP)
SET KMPVNSP=$ZDEFNSP
+8 SET KMPVTSK="KMPVRUN"
+9 IF KMPVNSP'=$ZDEFNSP
SET KMPVTSK=KMPVTSK_"_"_KMPVNSP
+10 SET KMPVMSG="CHECKING KMPV SETUP IN "_KMPVNSP_" NAMESPACE..."
+11 WRITE !,KMPVMSG,!!
+12 DO ##class(%SYS.System).WriteToConsoleLog("ZSTU: "_KMPVMSG,0,0)
+13 SET KMPVTFLG=0
+14 SET KMPVTSKS=##class(%ResultSet).%New("%SYS.TaskSuper.TaskListDetail")
+15 SET KMPVSTAT=KMPVTSKS.Execute()
+16 FOR
SET KMPX=KMPVTSKS.Next()
if KMPVTSKS.GetDataByName("ID")=""
QUIT
Begin DoDot:1
+17 IF (KMPVTSKS.GetDataByName("Task Name")=KMPVTSK)
Begin DoDot:2
+18 SET KMPVTID=KMPVTSKS.GetDataByName("ID")
+19 SET KMPVTRUN=KMPVTSKS.GetDataByName("Next Scheduled Date")_" at "_KMPVTSKS.GetDataByName("Next Scheduled Time")
+20 IF KMPVTSKS.GetDataByName("Suspended")'=""
Begin DoDot:3
+21 DO ##class(%SYS.Task).Resume(KMPVTID)
+22 SET KMPVMSG=KMPVTSK_" Task #"_KMPVTID_" Exists and Resumed to Run at "_KMPVTRUN
End DoDot:3
+23 IF '$TEST
SET KMPVMSG=KMPVTSK_" Task #"_KMPVTID_" Exists and Scheduled to Run at "_KMPVTRUN
+24 SET KMPVTFLG=1
+25 WRITE !,KMPVMSG
+26 DO ##class(%SYS.System).WriteToConsoleLog("ZSTU: "_KMPVMSG,0,0)
End DoDot:2
End DoDot:1
+27 ;
+28 ;create task if it doesn't exist
+29 IF 'KMPVTFLG
Begin DoDot:1
+30 SET KMPVTASK=##Class(%SYS.Task).%New()
+31 SET KMPVTASK.Name=KMPVTSK
+32 SET KMPVTASK.Description="Start VSM Collection Drivers"
+33 SET KMPVTASK.NameSpace=KMPVNSP
+34 SET KMPVTASK.TaskClass="%SYS.Task.RunLegacyTask"
+35
*** ERROR ***
SET KMPVTASK.Settings=$lb("ExecuteCode","D RUN^KMPVRUN")
+36 SET KMPVTASK.RunAsUser="_SYSTEM"
+37 SET KMPVTASK.Priority=0
+38 SET KMPVTASK.StartDate=$PIECE($HOROLOG,",",1)+1
+39 ;task.DailyFrequencyDisplayToLogical("Once")
SET KMPVTASK.DailyFrequency=0
+40 SET KMPVTASK.DailyFrequencyTime=""
+41 SET KMPVTASK.DailyIncrement=""
+42 SET KMPVTASK.DailyStartTime=60
+43 SET KMPVTASK.Expires=0
+44 SET KMPVTASK.DailyEndTime=""
+45 SET KMPVTASK.RescheduleOnStart=1
+46 SET KMPVSTAT=KMPVTASK.%Save()
+47
*** ERROR ***
IF $System.Status.IsError(KMPVSTAT)
Begin DoDot:2
+48
*** ERROR ***
SET KMPVMSG(1)="Error #"_$System.Status.GetErrorCodes(KMPVSTAT)
+49
*** ERROR ***
SET KMPVMSG(2)=$System.Status.GetOneStatusText(KMPVSTAT,1)
+50 SET KMPVMSG(3)="Failed to Create and Schedule Task "_KMPVTSK_" in Cache Task Manager"
+51 FOR I=1:1:3
WRITE !,KMPVMSG(I)
DO ##class(%SYS.System).WriteToConsoleLog("ZSTU: "_KMPVMSG(I),0,1)
End DoDot:2
QUIT
+52 SET KMPVMSG="Created and scheduled Task "_KMPVTSK_" in Cache Task Manager"
+53 WRITE !,KMPVMSG
DO ##class(%SYS.System).WriteToConsoleLog("ZSTU: "_KMPVMSG,0,0)
End DoDot:1
+54 QUIT
+55 ;
ENABLE(KMPNS,KMPABLE) ;
+1 NEW DA,DIC,DIE,DR,KMPMSG,KMPOPT,KMPOPTS,KMPTIEN,X,Y
+2 DO KMPOPTS(KMPNS,.KMPOPTS)
+3 SET KMPMSG=$SELECT(KMPABLE=1:"@",1:"Migrated to VSM MANAGEMENT. Contact CPEVSM@DOMAIN.EXT")
+4 SET KMPOPT=""
+5 FOR
SET KMPOPT=$ORDER(KMPOPTS(KMPOPT))
if KMPOPT=""
QUIT
Begin DoDot:1
+6 SET X=KMPOPT
+7 SET DIC=19
SET DIC(0)="B"
+8 DO ^DIC
+9 SET KMPTIEN=+Y
+10 IF KMPTIEN>0
Begin DoDot:2
+11 SET DIE=19
SET DA=KMPTIEN
SET DR="2///"_KMPMSG
DO ^DIE
End DoDot:2
End DoDot:1
+12 QUIT
+13 ;
KMPOPTS(KMPNS,KMPOPTS) ;
+1 KILL KMPOPTS
+2 IF KMPNS="KMPS"
Begin DoDot:1
+3 SET KMPOPTS("KMPS SAGG FILE")=""
SET KMPOPTS("KMPS SAGG MANAGER")=""
+4 SET KMPOPTS("KMPS SAGG REPORT")=""
SET KMPOPTS("KMPS SAGG STATUS")=""
+5 SET KMPOPTS("KMPS SAGG STOP")=""
End DoDot:1
+6 IF KMPNS="KMPD"
Begin DoDot:1
+7 SET KMPOPTS("KMPD BACKGROUND DRIVER")=""
SET KMPOPTS("KMPD CM DEVELOPER TOOLS")=""
+8 SET KMPOPTS("KMPD CM TOOLS MANAGER MENU")=""
SET KMPOPTS("KMPD CM TOOLS REPORTS")=""
+9 ;S KMPOPTS("KMPD ECHO")="" - LEAVE OPTION UNTIL REPLACED
+10 SET KMPOPTS("KMPD PARAM EDIT")=""
+11 SET KMPOPTS("KMPD STATUS")=""
SET KMPOPTS("KMPD TMG AVG HR TT")=""
+12 SET KMPOPTS("KMPD TMG AVG TTL")=""
SET KMPOPTS("KMPD TMG DLY TTL DETAIL")=""
+13 SET KMPOPTS("KMPD TMG HRLY TTL")=""
SET KMPOPTS("KMPD TMG HRLY TTL DETAIL")=""
+14 SET KMPOPTS("KMPD TMG HRLY TTL RT")=""
SET KMPOPTS("KMPD TMG MONITOR")=""
+15 SET KMPOPTS("KMPD TMG REPORTS")=""
SET KMPOPTS("KMPD TMG START/STOP")=""
+16 SET KMPOPTS("KMPD TMG TTL ALERT")=""
SET KMPOPTS("KMPD TMG TTL ALERT RT")=""
End DoDot:1
+17 QUIT
+18 ;
GLOSTATS(KMPDIRS) ;
+1 NEW B,KMPDIR,KMPRES,KMPSTAT,KMPSTATE,KMPVLN
+2 SET KMPVLN=1
SET B="|"
+3 SET KMPSTATE=##class(%SQL.Statement).%New()
+4 SET KMPSTAT=KMPSTATE.%PrepareClassQuery("%SYS.GlobalQuery","Size")
+5 SET KMPDIR=""
+6 FOR
SET KMPDIR=$ORDER(KMPDIRS(KMPDIR))
if KMPDIR=""
QUIT
Begin DoDot:1
+7 SET KMPRES=KMPSTATE.%Execute(KMPDIR,"","*")
+8 DO GLOSET(KMPDIR)
End DoDot:1
+9 QUIT
+10 ;
GLOSET(KMPDIR) ;
+1 NEW KMPALL,KMPNAME,KMPUSE
+2 FOR
SET KMPX=KMPRES.%Next()
if KMPRES.%Get("Name")=""
QUIT
Begin DoDot:1
+3 SET KMPNAME=KMPRES.%Get("Name")
+4 SET KMPALL=KMPRES.%Get("Allocated MB")
+5 SET KMPUSE=KMPRES.%Get("Used MB")
+6 SET ^KMPTMP("KMPV","VSTM","TRANSMIT","GLOBALS",$JOB,KMPVLN)=KMPDIR_B_KMPNAME_B_KMPALL_B_KMPUSE
SET KMPVLN=KMPVLN+1
End DoDot:1
+7 QUIT
+8 ;
ZERO() ;
+1 NEW B,KMPDATA,KMPFNUM,KMPGNAM,KMPVLN
+2 SET U="^"
SET B="|"
SET KMPVLN=1
+3 SET KMPFNUM=0
FOR
SET KMPFNUM=$ORDER(^DIC(KMPFNUM))
if '+KMPFNUM
QUIT
Begin DoDot:1
+4 if $GET(^DIC(KMPFNUM,0))=""
QUIT
+5 if '$DATA(^DIC(KMPFNUM,0,"GL"))
QUIT
+6 SET KMPGNAM=$GET(^DIC(KMPFNUM,0,"GL"))
if KMPGNAM=""
QUIT
+7 ; file num ^ file name ^ global root ^ version ^ entries ^ last id
+8 SET KMPDATA=KMPFNUM_B_$PIECE(^DIC(KMPFNUM,0),U)_B_KMPGNAM_B_+$GET(^DD(+$PIECE(^DIC(KMPFNUM,0),U,2),0,"VR"))_B_+$PIECE($GET(@(KMPGNAM_"0)")),U,4)_B_+$PIECE($GET(@(KMPGNAM_"0)")),U,3)
+9 SET ^KMPTMP("KMPV","VSTM","TRANSMIT","ZERO",$JOB,KMPVLN)=KMPDATA
SET KMPVLN=KMPVLN+1
End DoDot:1
+10 QUIT