Written by

Sr Application Development Analyst at The Ohio State University Wexner Medical Center
Question Scott Roth · Sep 13, 2022

Setting up Task for User Defined Class File

I have created a class file that I want to execute daily to gather Metrics (Message Header, Space Available, etc..) and write the data into a Cache table. Now that I have written the class I want to add it to the Task Scheduler within Ensemble to run every morning. How do I go about getting the class file created as a Task within the Task Scheduler? The Documentation isn't as clear cut for creating custom tasks as one would expect.

Product version: Ensemble 2018.1
$ZV: Cache for UNIX (IBM AIX for System Power System-64) 2018.1.3 (Build 414U) Mon Oct 28 2019 11:24:02 EDT

Comments

Eduard Lebedyuk · Sep 13, 2022

Check this example.

In short:

  1. Create class extending %SYS.Task.Definition
  2. Add properties - that's task settings
  3. Implement OnTask method, which returns %Status
  4. Set TaskName parameter

After that you can add a task of TaskName type from the SMP.

0
Krishnaveni Kapu  Mar 4 to Eduard Lebedyuk

Hi Eduard,

I have a scheduler task and associated class that works.

Class Sample.Util.CreateTask Extends (%SYS.Task.Definition, %Persistent)
{

Parameter PROPERTYVALIDATION = 1;

Parameter TaskName = "Sample.Util.CreateTask";

Method OnTask() As %Status
{
// Perform the logic
}

}

Is there a way to Enable or Disable the abbove task "CreateTask()" from an external function/Method/class ?

0
Jeffrey Drumm  Mar 4 to Krishnaveni Kapu

You can suspend the task via either ObjectScript or SQL.

Assuming you know the Task ID, and using 1001 as an example:

Set tsk = ##class(%SYS.Task).%OpenId(1001)
Set tsk.Suspended = 1Do tsk.%Save()

or

Do##class(%SYS.Task).Suspend(1001,1)

Resume the task with

Do##class(%SYS.Task).Resume(1001)

Via SQL:

UPDATE %SYS.Task SET Suspended = 1WHEREID = 1001

or

UPDATE %SYS.Task SET Suspended = 1WHERE TaskClass = 'Sample.Util.CreateTask'

Set Suspended to 0 to re-enable the task.

0
Ben Spead · Sep 13, 2022

@Scott Roth - you can create a New Task instance via the "Task Schedule Wizard" in the System Management Portal, and in the "Task Type" field, select "RunLegacyTask".  Then in the ExecuteCode field, simply type the command to run the desired method in your class.  Then you can enter the rest of the details of the Task accordingly (when to run, how often, etc) and it will make the call to your class whenever the Task runs.  

Please let me know if more clarification would be helpful.

0
Scott Roth  Sep 16, 2022 to Ben Spead

In "ExecuteCode" do you have to specify the "do ##class....." or can you just enter "##class...."

0
Ben Spead  Sep 16, 2022 to Scott Roth

It is the actual code as it will be executed, so "Do ##class...."

0
Alex Woodhead · Sep 13, 2022

I have an example implemetation in the Ompare tool.

See: https://github.com/alexatwoodhead/ompare/blob/main/src/cls/ompare/Sched…

Extends: %SYS.Task.Definition

Implements: OnTask method

By the way, you can run Schedules programatically from IRIS Session outside of the Task Scheduler if you are investigating / debugging the behaviour. For example:

settBASE=##class(ompare.Schedule).%New()
settBASE.Environment="BASE"settBASE.Namespaces="OMPARE-BASE,INST-*,-INST-TEMP"settBASE.RunSourceHandlers=1settBASE.ExportToFile=1settBASE.ExportDirectory="C:\TMP\ompare\"settBASE.ExportCompression=0settBASE.DiscardProfileData=1settBASE.RetainExportDays=0settBASE.IncludeSourceCode=1settSC1=tBASE.OnTask()

The reason I would subclass %SYS.Task.Definition is that the Management Portal knows how to display input configuration fields for your class properties.

This is more visably useful / supportable. Easier to see the task paramaters.

They can have validation also (Required, Pattern, MINLEN, MAXLEN, Setter methods, %OnSave methods).

Hope that helps :)

0