· May 23, 2023

Clone scheduled tasks

i'm working with an instance of IRIS that does a lot of integration (HS) and i need to schedule all the cleaning jobs for the productions.

Is there a way to "clone" the purge task for all the namespaces?

Product version: IRIS 2022.1
Discussion (3)2
Log in or sign up to continue

Here's the code to create task to purge messages in all interoperability namespaces:

set sc = ##class(%SYS.Namespace).ListAll(.result) 
kill result("%SYS"), result("HSCUSTOM"), result("HSLIB"), result("HSSYS"), result("REPO") 
while 1 {set ns = $o(result($g(ns))) quit:ns="" continue:$e(ns,1,2)="^^" set $namespace = ns continue:'##class(%Dictionary.ClassDefinition).%ExistsId("Ens.MessageHeader") set task=##class(%SYS.Task).%New(),task.Name = "Purge old Interoperability data in " _ $namespace,task.NameSpace=$Namespace,task.TimePeriod=0,task.TimePeriodEvery=1,task.DailyFrequency=0,task.DailyFrequencyTime="",task.DailyIncrement="",task.DailyStartTime = 3600,task.DailyEndTime = "",task.StartDate = $p($H,",",1)+1,task.Priority = 2,task.Expires = 0,taskdef = ##class(Ens.Util.Tasks.Purge).%New(),taskdef.BodiesToo = 1,taskdef.KeepIntegrity = 1,taskdef.NumberOfDaysToKeep = 1,taskdef.TypesToPurge = "all",sc = task.AssignSettings(taskdef),task.TaskClass=$classname(taskdef),sc = task.%Save()}

Cloning a particular task based on persistent class implementing %ConstructClone.

Can be good to have distinct names

set taskToCopyId=1000
set source=##class(%SYSTEM.Task).%OpenId(taskToCopyId)
for ns="FTP","WSDL","X12" {set copy=source.%ConstructClone()  set copy.JobGUID=""  set copy.Name=source.Name_" "_ns  set copy.NameSpace=ns  write !,ns," result ",copy.%Save()}

Can see other properties might want to reset via OBJ.Dump

set taskToCopyId=1000
set source=##class(%SYSTEM.Task).%OpenId(taskToCopyId)
do $SYSTEM.OBJ.Dump(source)