Scott Roth · Sep 13

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
0 136
Discussion (5)2
Log in or sign up to continue

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.

@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.

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

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

I have an example implemetation in the Ompare tool.


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:

set tBASE=##class(ompare.Schedule).%New()
set tBASE.Environment="BASE"
set tBASE.RunSourceHandlers=1
set tBASE.ExportToFile=1
set tBASE.ExportDirectory="C:\TMP\ompare\"
set tBASE.ExportCompression=0
set tBASE.DiscardProfileData=1
set tBASE.RetainExportDays=0
set tBASE.IncludeSourceCode=1
set tSC1=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 :)