The Attivio Platform uses the Quartz Enterprise Job Scheduler to manage and trigger scheduled events within the system. The scheduler module comes with a service component, the SchedulerService, that encapsulates the integration of the Quartz scheduler. It also ships with a Java client class,
SchedulerClient , you can use to interact with the
SchedulerService, providing methods for managing scheduled tasks, as well as pausing and resuming the scheduler.
These features require the inclusion of the scheduler module when you run createproject to create the project directories.
View incoming links.
Configuring the Scheduler Service
You can activate the scheduler in any Attivio project using the createproject tool. Including the scheduler module in a custom configuration configures the scheduler for the new project. When using a multi-node topology you must add a service location for the scheduler as follows. Only a single instance of the scheduler across all nodes is necessary so you can set the
mySchedulerNodeSet below with a single node/nodeset name.
The default scheduler configuration registers an in-process receiver called scheduler and a remote input with URI:
Under the default configuration the baseport is 17000. When using https via for all endpoint communication, you must add 2 to the baseport. With the default port configuration and the scheduler configuration shown above, the URL looks like this:
If using https:
Managing Scheduled Tasks
Create a SchedulerClientFactory and using the factory, create a SchedulerClient pointing to the external HTTP endpoint for the scheduler service as follows:
Scheduling a new task by invoking the
'saveTask' method on the client, passing in the name of the new task, owner and schedule, as well as the job implementation class that handles the triggered job (for details, see Cron-based Schedule Formats and Implementing a Custom Job).
Together, the owner and name form the unique identifier for a task. Updating the task require passing true as the second argument to the saveTask() method to indicate that you want to overwrite the existing task with the same name and owner.
To update the task without overwriting an existing one, pass false as the second argument to the saveTask() method. You can check to see if the task was overwritten by looking at the return value.
To deleting a task, do the following:
Additionally, the client supports operations to pause the scheduler engine. This stops the firing of scheduled tasks, and resume operation again:
Below is a test program that uses the code samples above:
Cron-Based Schedule Formats
Attivio uses Quartz's CronTrigger implementation – a modified UNIX cron-style string format to represent a recurring schedule – for all scheduling.
At its simplest, the cron format supplies the second, minute, hour, day (either date or day of the week), month, and year when a task should be triggered, supporting wildcards for each value for schedule recurrence. This is represented by six values (with an optional seventh), separated by spaces, for example,
"* * * * * ?". The order of the values within the expression is illustrated in the table below, along with some typical examples.
Fire every second of every hour of every day
Fire every day at 3AM
Fire every minute, on the 30th second
Fire once a month, at 9AM on the 1st
Fire every Saturday at midnight
Fire every Saturday at midnight (alternative)
Fire on July 4th, 2076 at 2:15PM
These are the most basic usages of the cron format. Each value can also contain lists ("15,30" in "days of month" fires on the 15th and 30th), ranges ("9-17" in hours only fires between 9AM and 5PM), base + offset ("2/5" in minutes fires every 5 minutes, starting at 2 minutes after the hour, i.e. :02, :07, :12, etc), "n-th" values ("6#3" in "day of week" fires on the third Friday of every month, where Friday is the 6th day of the week).
See Quartz's CronTrigger Tutorial for a complete explanation.
Be aware that the
SchedulerClient.updateTask methods throw exceptions if invalid cron expressions are supplied.
Implementing a Custom Job
After scheduling a task to trigger, implement a job that does something useful once is triggered. To do this, create a new class that implements the
com.attivio.model.AttivioScheduledJob interface. This interface defines one method:
When the scheduler determines that it is time to trigger a task, it does the following:
- Loads the
jobClassNameargument supplied when the task was scheduled/updated.
- Creates a new instance of the job class.
Packages the task name, owner, and any other relevant metadata into a Java Map.
executemethod of the job implementation, passing in the metadata Map as the argument.
The scheduler may invoke the
execute method of several task instances concurrently, so the implementation must perform appropriate synchronization if shared resources are used.
Because Attivio loads the job implementation class, you must put the class in the Attivio classpath.
Note that the
SchedulerService validates the supplied
jobClassName by verifying that: the class exists, and can be loaded. It then implements the
AttivioScheduledJob interface. This means that Attivio requires access to the class both at task scheduling time and at task execution time.
Also note that the job class need NOT be accessible to whatever process is using the
SchedulerClient. The client deals only with the string representation of the class name. This is useful if a scheduler UI is running on a separate machine from Attivio.
The following is a basic example of a custom job implementation class.
When creating a new job implementation, put the jar containing the job class into the <install_dir> /lib or <project_dir> /lib directory and restart the Attivio node before scheduling the job.
You can schedule connectors to run automatically at predetermined times or intervals.
Scheduling a Connector from the Command Line
The following command runs the connector named "dbConnector" every 30 minutes.
It assumes that "dbConnector" connector is already configured on the system.
Scheduling a Connector from the Connector Editor
The advantage of using the connector editor is that the UI helps you work out the cron parameters.
Scheduling Common Index Tasks
Attivio provides functionality to support periodic commits, refreshes, optimizations, and backups of an index.
Sample Configuration File
To schedule index tasks, define a bean for each task in a configuration XML file in your
<project-dir>/conf/bean directory, along these lines:
These scheduled tasks should take effect after you next deploy the modified project configuration.
messageUri value should point to the ingest workflow that contains the content-dispatcher component for your index. By default, this is the
indexer subflow, which contains the
index-content-dispatcher component for the default index with name
index. If you want to commit a different index, you will need to replace
indexer with the appropriate workflow name in the above configuration.
Attivio does not recommend committing the index more often than every 15 minutes.