1 | initial version |
Quartz is a job scheduling framework that can be utilized in Grails to perform common tasks like data backup, email notifications, and report generation. Here’s how it can be used in Grails:
plugins {
runtime ":quartz:2.1.6"
}
class BackupJob extends QuartzJobBean {
void executeInternal(JobExecutionContext context) throws JobExecutionException {
// execute backup job logic here
}
}
org.quartz.jobBackupJob.name = BackupJob
org.quartz.jobBackupJob.group = Backup
org.quartz.jobBackupJob.description = Scheduled backup job
org.quartz.jobBackupJob.concurrency = 1
org.quartz.jobBackupJob.requestRecovery = true
org.quartz.triggerBackupJob.type = CronTrigger
org.quartz.triggerBackupJob.cronExpression = 0 0 12 * * ?
class BootStrap {
def init = { servletContext ->
JobDetail job = newJob(BackupJob.class)
.withIdentity("jobBackupJob", "Backup")
.storeDurably(true)
.build()
CronTrigger trigger = newTrigger()
.withIdentity("triggerBackupJob", "Backup")
.withSchedule(cronSchedule("0 0 12 * * ?"))
.build()
scheduler.scheduleJob(job, trigger)
}
}
This code will create a new instance of the BackupJob class, configure the job with the properties defined in the Quartz properties file, and schedule the job to run every day at noon.