Martini Invoking Services via a Scheduler Trigger
Overview
The Scheduler trigger enables developers to configure services to execute at specified schedules or fixed intervals. This functionality is crucial for automating tasks that need to run periodically, such as data synchronization, routine maintenance, or batch processing.
Prerequisites
- Understanding of Martini services and triggers.
- Knowledge of cron expressions for cron scheduling.
Configuration
General Configuration
Refer to the general trigger configuration documentation for initial setup steps and parameters applicable to all triggers.
Scheduler-specific Configuration
The Scheduler trigger can be configured to execute tasks based on a simple repeating interval or a cron expression.
Properties
Property | Default | Description |
---|---|---|
Type | Simple Repeating |
The frequency of execution, configurable as either a cron expression or a simple fixed interval. |
Stateful | false |
If true, preserves the JobDataMap for subsequent executions and prevents concurrent execution. |
Schedule Types
- Simple Repeating: Executes the service at a fixed interval, specified in seconds.
- Cron: Utilizes cron expressions for precise scheduling, akin to the Unix
cron
utility.
Examples of Scheduler Configuration
Simple Repeating
To configure a service to execute every 300 seconds:
1 2 |
|
Cron
To schedule a service to run at 3 AM on weekdays:
1 2 |
|
Service Parameters
Scheduler-specific Parameters
Services invoked by the Scheduler trigger can access specific contextual information through parameters.
Name | Type | Description |
---|---|---|
context |
org.quartz.JobExecutionContext |
Provides the execution context from Quartz. |
jobDataMap |
org.quartz.JobDataMap |
A map for passing data between executions of the job. |
job |
org.quartz.Job |
The Quartz job instance being executed. |
Troubleshooting and FAQs
Troubleshooting
- Problem: Service not executing as scheduled.
- Solution: Check the schedule configuration for accuracy. Ensure the Martini server's time zone aligns with the expected execution times.
Example
Groovy Script as Service
Consider a Groovy script that prints available variables in the context when the Scheduler trigger is activated. This script showcases how to access execution context and other parameters provided by the Scheduler trigger.
1 2 3 |
|
Upon activation, the console will display logs similar to the following, illustrating the contextual information available to the script:
1 2 3 4 5 6 7 8 9 |
|
Groovy Function as Service
A function within a Groovy class can also be designated as a service for the Scheduler trigger. The following example replicates functionality similar to sending scheduled emails, demonstrating practical use of the Scheduler trigger for automated tasks:
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 |
|