How to run a process on an interval or schedule?
Source: Dev.to
Source: Dev.to – How to run a process on an interval or schedule
Interoperability – Running a Process on an Interval or Schedule
When I started my journey with InterSystems IRIS, especially in Interoperability, one of the first questions I had was:
“How can I run something on an interval or schedule?”
Below are two simple classes that solve this problem. They are intended as quick‑start snippets for beginners, not a full‑blown production solution.
(The original article continues with the class definitions and usage examples.)
The Scenario
We need to “take some data from an API and put it into an external database.”
The solution is built from three pre‑existing components:
| Component | Purpose |
|---|---|
Ens.BusinessProcess | Implements the data‑flow algorithm (prepare request, transform response, handle errors, etc.). |
EnsLib.REST.Operation | Performs the HTTP request to the API (uses EnsLib.HTTP.OutboundAdapter). |
Ens.BusinessOperation | Writes the retrieved data to the external DB via EnsLib.SQL.OutboundAdapter (JDBC). |
The hosts for these components are already in place, so they are out of scope for this task.
What’s missing?
We still need an Initiator that:
- Runs on a scheduled interval.
- Sends a dummy request to the
Ens.BusinessProcessto trigger the workflow.
1. Interval Initiator – Util.Service.IntervalCall
/// Call targets by interval
Class Util.Service.IntervalCall Extends Ens.BusinessService
{
/// List of targets to call
Property TargetConfigNames As Ens.DataType.ConfigName;
/// If true, calls are made asynchronously (SendRequestAsync)
Property AsyncCall As %Boolean;
/// If true, and the target list contains more than one target,
/// the process will stop after the first error
Property BreakOnError As %Boolean [ InitialExpression = 1 ];
Property Adapter As Ens.InboundAdapter;
Parameter ADAPTER = "Ens.InboundAdapter";
Parameter SETTINGS = "TargetConfigNames:Basic:selector?multiSelect=1&context={Ens.ContextSearch/ProductionItems?targets=1&productionName=@productionId},AsyncCall,BreakOnError";
/// Main entry point – called by the service interval
Method OnProcessInput(pInput As %RegisteredObject,
Output pOutput As %RegisteredObject,
ByRef pHint As %String) As %Status
{
Set tSC = $$$OK
Set targets = $LISTFROMSTRING(..TargetConfigNames)
Quit:$LISTLENGTH(targets)=0 $$$ERROR($$$GeneralError, "TargetConfigNames are not defined")
For i=1:1:$LISTLENGTH(targets) {
Set target = $LISTGET(targets, i)
Set pRequest = ##class(Ens.Request).%New()
If ..AsyncCall {
Set tSC = ..SendRequestAsync(target, pRequest)
} Else {
Set tSC = ..SendRequestSync(target, pRequest, .pResponse)
}
Quit:($$$ISERR(tSC) && ..BreakOnError)
}
Quit tSC
}
/// Populate the Production UI with the selected targets
ClassMethod OnGetConnections(Output pArray As %String, pItem As Ens.Config.Item)
{
If pItem.GetModifiedSetting("TargetConfigNames", .tValue) {
Set targets = $LISTFROMSTRING(tValue)
For i=1:1:$LISTLENGTH(targets) Set pArray($LISTGET(targets, i)) = ""
}
}
}How to use it
- Add the class to a Production.
- In the TargetConfigNames setting, select the business process (or any other target) you want to invoke.
2. Scheduled Initiator – Util.Task.ScheduleCall
When the requirement changes to “run every Monday at 08:00 AM”, the best approach is to use Task Manager.
Create a custom task that launches the initiator programmatically:
/// Launch selected business service on schedule
Class Util.Task.ScheduleCall Extends %SYS.Task.Definition
{
Parameter TaskName = "Launch On Schedule";
/// Business Service to launch
Property ServiceName As Ens.DataType.ConfigName;
Method OnTask() As %Status
{
#dim tService As Ens.BusinessService
Set tSC = ##class(Ens.Director).CreateBusinessService(..ServiceName, .tService)
Quit:$$$ISERR(tSC) tSC
Set pRequest = ##class(Ens.Request).%New()
Quit tService.ProcessInput(pRequest, .pResponse)
}
}Important notes
- Pool Size of the Initiator Business Service must be set to 0. This disables the built‑in “Call Interval” mechanism (you can clear the interval or leave it – it won’t be used when the pool size is 0).
- In Task Manager, create a new task:
- Choose “Launch On Schedule” as the task type (don’t forget to select the correct namespace).
- Set the
ServiceNameparameter to the name of the Initiator Business Service you created. - Define the desired schedule (e.g., every Monday at 08:00).

Recap
| Class | What it does |
|---|---|
Util.Service.IntervalCall | Runs on a configurable interval, sending a request to one or many targets. |
Util.Task.ScheduleCall | Schedules the same initiator via Task Manager, giving you full cron‑style control. |
Both classes are lightweight, easy to add to any Production, and provide a solid foundation for beginners who need to trigger Interoperability processes on a schedule.
Scheduling a Task
To create a new scheduled task, navigate to:
System Operation > Task Manager > New TaskBonus: Running a Task On‑Demand
Sometimes you need to run something in Production only on demand. Instead of building a custom UI on CSP, use the standard Management Portal UI.
- Change the task’s Run Type to On Demand.
- The on‑demand task list is available at:
System > Task Manager > On‑demand Tasks- Click the Run button to execute the task immediately.
Note: The Run button (manual run) is available for any kind of task.
Summary
You now have a clean architecture for interoperability across your business hosts, with three ways to run your data grabber:
- By interval
- On a timetable
- Manually (on demand)

