Skip to content

Overview

Concepts and Principles

Development

Overview

IDEs

API Explorer

Releases

Release Notes

TORO Integrate

Coder Studio

Coder Cloud

Bug Reports

Search

Scheduler Endpoint

The Scheduler Endpoint enables developers to configure services that execute at a given schedule or fixed interval.

Properties

Property Default Description
Schedule The frequency of execution. May be in the form of a cron expression, or a simple fixed interval.
Service The service to execute when the endpoint is triggered
Run As 'Anonymous' The user to run the service on behalf of. This is logged to tracker.
Log to Tracker false Flag determining whether executions should be logged to the tracker
Document Type 'Scheduler' The document type to be registered to the tracker when this endpoint is triggered
Stateful false When checked, the JobDataMap is persisted to preserve state for the next execution. Stateful jobs also disallow concurrent execution, which means triggers before the completion of an running execution are delayed.

Schedule Types

There are two ways to configure schedules:

  1. Simple Repeating - accepts a non-negative number that denotes the interval, in seconds, at which the service will be executed.

  2. Cron - like the Unix cron utility, this type allows a more fine-grained schedule configuration. The UI supports easy management of such expressions:

Scheduler Endpoint | Cron

The above example becomes equivalent to the cron expression: * 3 * * 1-5, which stands for at every minute past hour 3 on every day-of-week from Monday through Friday.

Service

When the endpoint is triggered, the following variables are exposed to the configured service:

Name Type Description
parameters java.util.Map Contains all the variables below
esbPackage ESBPackage The Integrate Package that contains this endpoint
properties java.util.Map Contains all the properties associated with the endpoint
context org.quartz.JobExecutionContext The Quartz context
jobDataMap org.quartz.JobDataMap The Quartz job data map
job org.quartz.Job The Quartz job
internalId java.lang.String Tracker internal ID. If the endpoint was configured to not track, this value will be null

Examples

Gloop as a Service

Consider this integration using Gloop that sends an email to various recipients on schedule:

SendScheduledEmail's configuration

(1) Takes the credentials of the email sender from the package properties.
(5) Iterates the to variable, containing a list of recipient emails.
(6) Constructs the email body using Velocity as templating language.
(7) Sends the email to each recipient.

More Gloop

The distribution ships with an Integrate package called examples, which contains services (including the above example) demonstrating more use cases.

Groovy Script as a Service

Consider this Groovy script that simply prints the available variables in the context:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
[ 
    'parameters',
    'esbPackage',
    'properties',
    'context',
    'jobDataMap',
    'job',
    'internalId' ].each {

    println "$it\t : " + this[it]
}

When the endpoint is triggered - in this case, the schedule is met - the console prints accordingly:

1
2
3
4
5
6
7
parameters   : [ <omitted> ]
esbPackage   : ESBPackage [name=examples]
properties   : [ <omitted> ]
context  : JobExecutionContext: <ommitted>
jobDataMap   : [ <ommitted> ]
job  : io.toro.integrate.core.endpoint.impl.vfs.VFSClientJobWrapper@5f10fee7
internalId   : null

Groovy Method as a Service

We can also use a method of a Groovy class as a service for the endpoint. The following is an example that replicates Gloop's SendScheduledEmail:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class SchedulerExamples {

    void sendScheduledEmail() {
        String email = 'login'.getPackageProperty()
        String password = 'password'.getPackageProperty()
        String port = 'port'.getPackageProperty()
        String subject = 'subject'.getPackageProperty()
        String[] to = 'email.bulk.to'.getPackageProperty().split(',' )
        String protocol = 'protocol'.getPackageProperty()
        String server = 'server'.getPackageProperty()

        to.each {
            String body = '''<html>
            <head></head>
            <body>
                Hello $name!,<br/>
                This is an email from TORO Integrate!<br/>
                <br/>
                Thanks,<br/>
                TORO
            </body>
            </html>
        '''.parse([name: it])
            "${protocol}://${URLEncoder.encode(email, 'UTF-8')}:${URLEncoder.encode(password, 'UTF-8')}@${server}:${port}/${subject}"
                    .send([to: it], body)
        }

    }

}