Question Alexandr Ladoshkin · Dec 27, 2018

Call method in background process

Hello everybody.

I have task to find out possibility call method from background task.  I need run some class with methods. I've found out than I can run it via ^%ZSTART routine. And now I wanna to learn is it possible to call this class and run it's methods.

Thank you

Comments

Julian Matthews · Dec 27, 2018

Hi Alexandr.

If you are looking to run a task at specific times, you could create a new task which extends %SYS.Task.Definition to then be selectable as an option from the task manager.

For example, I have a folder which I need to periodically delete files older than x days.

To achieve this, I have a class that looks like this:

Class DEV.Schedule.Purge Extends %SYS.Task.Definition{Parameter TaskName = "Purge Sent Folder";Property Directory As %String;Property Daystokeep As %Integer(VALUELIST = ",5,10,15,20,25,30") [ InitialExpression = "30" ];Method OnTask() As %Status{Set tsc = ..PurgeSentFolder(..Directory,..Daystokeep,"txt")Quit tsc}Method PurgeSentFolder(Directory As %String, DaysToKeep As %Integer, Extention As %String) As %Status{// Calculate the oldest date to keep files on or afterset BeforeThisDate = $zdt($h-DaysToKeep_",0",3)// Gather the list of files in the specified directoryset rs=##class(%ResultSet).%New("%File:FileSet")Set ext = "*."_Extentiondo rs.Execute(Directory,ext,"DateModified")// Step through the files in DateModified orderwhile rs.Next() {set DateModified=rs.Get("DateModified")if BeforeThisDate]DateModified {// Delete the fileset Name=rs.Get("Name")do ##class(%File).Delete(Name)}// Stop when we get to files with last modified dates on or after our delete dateif DateModified]BeforeThisDate set tSC = 1}quit tSC}}

Then I created a new task in the scheduler, selected the namespace where the new class exists, and then filled in the properties and times I want the task to run.

0
Alexandr Ladoshkin  Dec 27, 2018 to Julian Matthews

Thank you very much. I meant that one job which is everything in process waits for being called with another. One process call other

0