How To Execute Cron Job In Testing Environment
Posted By : Manish Kumar Narang | 28-Feb-2018
I have been using Grails from quite some time. People who are coming from Java background will find it very familiar. In fact, you can write java code in grails and it will work perfectly. The world of grails is more uncluttered where the idea is to follow convention over configuration.
One of my tasks was to schedule the
class SampleJob {
static triggers = {
cron cronExpression: "0 30 22 * * ? *" // execute job everyday at 10:30 pm
}
def execute() {}
}
The above code defines a cron job named SampleJob. The time at which this cron job is triggered is determined by the cron expression and execute() method contains the code which will be executed. The fields of the cron expression can be understood as follows -
cronExpression: "s m h D M W Y" | | | | | | `- Year [optional] | | | | | `- Day of Week | | | | `- Month | | | `- Day of Month | | `- Hour | `- Minute `- Second
But the stumbling block for our team was that the code wouldn't execute in the testing environment. We went through the Plugin Documentation and found the following -
By default, jobs will not be executed when running under the test environment.
But the documentation doesn't clearly state how to execute them under the test environment if one wants to. In
quartz {
autoStartup = true
jdbcStore = false
waitForJobsToCompleteOnShutdown = true
exposeSchedulerInRepository = false
props {
scheduler.skipUpdateCheck = true
}
}
environments {
test {
quartz {
autoStartup = true
}
}
}
It can be observed that jobs can be enabled/disabled for other environments also.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Manish Kumar Narang
Manish is an experienced Backend Developer with several years of industry experience in the IT field. He possesses a wide range of skills, including expertise in Backend languages like Core Java, J2EE, Hibernate, Spring/Spring Boot, and Python. Manish is also proficient in relational databases such as MySQL, PostgreSQL, and Oracle. He has hands-on experience in API implementations, web services development, testing, and deployments. Manish has contributed to various internal and client projects, including PMO, Catalyst, Communication-Scaffold, Oodles-Dashboard, and Devops Support, delivering significant business value. He is known for his innovative mindset and excellent problem-solving abilities. He keeps himself updated with new technologies by reading about them. He is skilled at collaborating closely with clients to define project scope and requirements, establish project timelines and milestones, and manage expectations. Manish conducts regular project status meetings, ensuring regular updates to clients and stakeholders regarding project progress, risks, and issues. Additionally, he serves as a mentor and coach to junior developers, offering guidance on project management best practices and fostering their skills development.