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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-19 15:45:43 +0000
Seen: 17 times
Last updated: Jun 19 '23
How to choose specific parameters while selecting inputs in Jenkins (Groovy) Pipeline?
What is the process of serializing groovy traits using Gson?
What is the method to transform an XML hierarchical arrangement to CSV utilizing groovy?
How to modify the node label in Jenkins once the job has been completed successfully?
What are the typical approaches found in a Gradle build script?
How can a list of objects in Groovy be created from Json?
How to provide the workspace path as a file to setReportDir in XmlTestRunListener using groovy?