Scheduler
The scheduler in bemoko can be use to run periodical or asynchronous jobs, e.g. regular "cron" tasks or send an email asynchronously.
Configuration
The scheduler is by default enabled from v1.8. Prior to this you will need to enable the scheduler in the platform configuration.
-Dbemoko.scheduler.enabled=true
Scheduling a Job
Create a plugin, e.g. mysite.MyJob
package mysite
import com.bemoko.live.platform.mwc.scheduler.BemokoJob
class MyJob extends BemokoJob {
public void execute() {
// Job logic ...
}
}
And then schedule the job, e.g. with site plugin that schedules the job in the initialise method
class MyJobScheduler {
def initialise() {
JobDetail myJob = JobBuilder.newJob(LicenseAlertJob.class)
.withIdentity("licenseAlertJob", "mysite").build()
Trigger myTrigger = TriggerBuilder.newTrigger()
.withIdentity("licenseAlertTrigger", "mysite")
.withSchedule(CronScheduleBuilder.cronSchedule("0 0 0 * * ?")).build()
def jobs = new HashMap()
jobs.put(myJob,[myTrigger])
Bemoko.scheduler.scheduleJobs(jobs,true)
}
}
with the the plugin registered at
<content-sources>
<source name="welcome.WelcomeScheduler" scope="site"/>
</content-sources>
Quartz
bemoko uses the Quartz API for scheduling - see the Quartz Documentation for more assistance how writing jobs and triggers.
You can configure the scheduler with the standard quartz configuration properties, e.g. to configure the number of threads available to the scheduler
-Dbemoko.scheduler.org.quartz.threadPool.threadCount=20