Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.Opens in a new tab

For information on migrating to InterSystems IRISOpens in a new tab, see Why Migrate to InterSystems IRIS?

Sample.Task

class Sample.Task extends %SYS.Task.Definition

Task definition is divided into two sections - The task schedule; when it will run - The task class; what it will do when it is running Generally tasks should be scheduled using the system management portal. If you need to schedule tasks programatically you can find examples at the bottom of this class. A series of task classes are defined to demonstrate potential usage For these examples we rely on the MailServer being set System Management Portal [Home]> [Configuration] > [Task Manager Settings] > [E-Mail Settings] The SMTP server must be defined, also any authorization which is required for the mail server Sample.Task Demonstrate what happens when a task encounters a runtime error Sample.TaskExample1 Demonstrates a task which fails every other time it executes Sample.TaskExample2 Using output files Sample.TaskExample3 Demonstrates how to look for problems with your tasks (not running) Edit this class and change the who@somecompany.com to your email address

Property Inventory

Method Inventory

Properties

property RunCount as %String;
Property to keep track of how many times this task has run
Property methods: RunCountDisplayToLogical(), RunCountGet(), RunCountIsValid(), RunCountLogicalToDisplay(), RunCountLogicalToOdbc(), RunCountNormalize(), RunCountSet()

Methods

method AlternativeOnTask() as %Status
Assuming that you want to handle an error it is safe do the following it is just unsafe to Set $ZT="^%ETN" as this ends with a Halt
method OnTask() as %Status
Demonstrate what happens when a task encounters a runtime error The first time the task runs, it will succeed The second time the task runs The task will be marked as suspended The third time the task runs The task will be marked as suspended An error will be generated in the system error trap Trapping errors using %ETN is already performed, therefore you should NOT set $ETRAP="^%ETN" ($ZT) this will cause the process to Halt and not clean up properly Never end the method by using HALT as this will cause the same problem as using ^%ETN This does not mean that you can't trap and handle your errors. See the AlternativeOnTask method which demonstrates how you can handle expected problems
classmethod ScheduleAfterAnother() as %Status
this will schedule a task to run after another task has completed since JournalSwitch happens on all systems we will use that as our trigger task but any task could easily be substituted
classmethod ScheduleHourly() as %Status
Example code to demonstrate programatically scheduling a task to run EveryHour between 9am - 5pm In this example Expires=0 and therefore the task will run every time it is scheduled, this is useful for cases where reports need to be generated based on a certain time, the report needs to be run after the time has passed, it can't be skipped. In this case you would probably use ..%RunDate and ..%RunTime in the OnTask method
classmethod ScheduleMonthly() as %Status
Schedule task to run monthly on the first Monday at 5:00 am
classmethod ScheduleOnceDaily() as %Status
this will schedule a task to run Once every day at 10:30 am this example does not take into account any task 'Settings' In this example, if the task has not run within 18 hours and 30 minutes of the scheduled start it will "Expire" and not run again until the next start time
classmethod ScheduleWeekly() as %Status
Schedule task to run weekly at 3:00 am on Wednesday between January 31, 2014 and February 15, 2014 In this example, if the task has not run within 5 days of the scheduled start it will "Expire" and not run again until the next start time
classmethod SuspendAndResumeTask() as %Status
example programatically suspending and then resuming a task

Inherited Members

Inherited Properties

Inherited Methods

Subclasses

FeedbackOpens in a new tab