Grails 3 Quartz plugin: Job doesn't start - grails

I am trying to do a simple background job in Grails. I just want stuff to happen every 30 seconds or so.
I am using Grails 3.1.3
I've added Quartz to my dependencies:
compile "org.grails.plugins:quartz:2.0.1"
Then I've run a compile and restarted the grails CLI. Now I created a Job via create-job. It looks like this:
package htwp
class UserSyncJob {
static triggers = {
simple repeatInterval: 5000l // execute job once in 5 seconds
}
def execute() {
println ("?")
log.error("??!")
throw new Error("JOB WHERE ARE YOU");
}
}
Nothing happens when I start the server via run-app. Nothing printed, no errors either.
What am I doing wrong?

I checked issues of quartz plugin for Grails project and found this issue and this issue.
Just upgrade as I said earlier in comment to the newest realese of plugin.

Related

Grails 3.3.8 does not reload the changes made to the project

I have a project with grails 3.3.8, the problem is that once I edit a controller or a gsp file, the changes are not reflected in the web browser even though the following message appears when it detects a change:
Controller.groovy change, compiling...
I have tried to start the app in the following way:
grails -reloading run-app.
And also with:
// File: build.gradle
import grails.util.Environment
...
bootRun {
final Boolean reloadEnabled =
Boolean.valueOf(
System.properties[Environment.RELOAD_ENABLED])
if (reloadEnabled) {
systemProperty Environment.RELOAD_ENABLED, reloadEnabled
}
}
...
grails -Dgrails.env=custom -Dgrails.reload.enabled=true run-app
According to this link https://intellij-support.jetbrains.com/hc/en-us/community/posts/207602705-Grails-3-not-automatically-hot-swapping-changed-code-after-upgrading-to-2016-1-3 it appears that hot reloading of classes only suns to happen in grails 3.3.x when the environment is set to development.
I've not been able to confirm that for myself however. I notice you are providing "custom" as your environment. Maybe try changing it to the development environment and see if that helps.
Also just want to confirm that your not just seeing behaviour listed in Grails auto recompile never completes (Grails 3.3.6)

sequential processing for n number of times in jenkins pipline

I have a jenkins pipeline to do parallel processing like below
buildNumber=[:]
buildIterations.each{
buildNumber[x]=createExecution(it)
}
node('MyJenkins'){
stage{'Prepare database')
--------
}
parallel buildNumber
def createExecution(String number){
cmd = {
node('MyJenkins'){
stage('Build'){
---------------------
}
stage('Test'){----------}
stage('package'){--------}
}
return cmd
}
But now i want to change this script to have sequential execution as this will run many builds in one job and have load on database at same time.
//should be executed once
node('MyJenkins'){
stage{'Prepare database')
--------
}
//should be executed one after the other, but below code isn't even considered for job. It just stops after prepare database
buildIterations.each{
number=it
node('MyJenkins'){
stage('Build'){
---------------------
}
stage('Test'){----------}
stage('package'){--------}
}
}
I am new to scripting, please help me know what mistake i am doing
which versions of the pipeline plugins are you using? Earlier versions didn’t support iterating an object using .each{}. Sometimes this resulted in the behavior you described. An update of the groovy-cps plugin most probably will do. Version 2.33 is the absolute minimum. I‘d go for latest if possible.
See groovy-cps plug-in
See also: JENKINS-26481

Grails auto-reloading new controller actions

I've
created new Grails 2.4.3 project
created TestController
set grails.reload.enabled = true in BuildConfig.groovy
run application with grails -reloading run-app
My controller action code:
def index() {
render "test"
}
When I change the string test to test2- I see in console (in Eclipse):
..................
|Compiling 1 source files
And after reloading page I see test2 - ok.
But when I try to add new method:
def test3() {
render "test3"
}
I see:
Why? Why there isn't even the url?
Example - action does't exist:
Interesting thing is - when I create a whole new controller the index action of the newly created controller works...
EDIT
After a while I decided to go with spring-boot and as a matter of fact - there it's not working either. I think that springloaded is the issue here because it doesn't pick up added new method in #Controller
I've asked the same question on github repo.
It seems that latest spring-loaded SNAPSHOT is working fine.
But it must be integrated into Grails - maybe in the next release unfortunately :(
Solution that works for me:
1) Versions:
IDE: Intellij IDEA 14.1.3
JDK: jdk1.7.0_25
GRAILS: 2.5.0
2) On BuildConfig.groovy:
grails.reload.enabled = true
grails.project.fork = [
test: false,
run: false,
]
3) Originally, my code was compiled on grails 2.4.4, so I upgraded to 2.5.0. I had no problems with the version change with plugins or anything. My guess is this works because it uses later versions of spring-loaded. Steps:
set-grails-version 2.5.0
clean
delete directory work (just to be sure, I don't really know if this is good practice)
compile and/or go to number 4
4) Debug Idea with this configuration: run-app -reloading
Works perfect, no forked debug, reloading enabled, no console error after reload and all breakpoints working even after code changes!
I took the liberty of reporting this issue to Grails.

Grails Functional Testing Plugin and RESTful Tests

I just grabbed the latest version of the functional testing plugin and it's focus, at least from the docs, has changed a bit. This is not a bad thing. The HtmlUnit integration is nice. But now, there isn't anything in the docs about RESTful testing of web services. However, what I used to do with functionaltestplugin.FunctionalTestCase still works, which is great.
For example:
void testCertifyEmployerCertifierNotFound() {
post('/employerCertification/certifyEmployer') {
headers['Content-Type'] = 'application/json'
body {
"""
{
'employerName': 'ACME',
'certifierExteralId': '1234556',
'certifyingUserId': '123445'
}
"""
}
}
assertStatus 200
assertContentType "application/json"
def model = this.response.contentAsString
def map = JSON.parse(model)
assertFalse(map.success)
assertNotNull(map.errorCode)
assertTrue(map.errorCode == EmployerCertificationService.ERROR_RESPONSE.CERTIFIER_NOT_FOUND.toString())
}
Is this plugin still the "defacto" plugin to use for functional web service testing and is my approach above still valid?
if your target is testing REST request/response I suggest you to use rest client builder plugin. You don't need complex browser-simul plugins. Use it is very simple in just two steps after installing it:
add event to manage functional tests in scripts/_Events.groovy: this is a system grail file used to hook some events at runtime. Just copy and paste this snippet:
eventAllTestsStart = {
if (getBinding().variables.containsKey("functionalTests")) {
functionalTests << "functional"
}
}
Now you can create functional tests in test/functional folder, rememeber to ends filename with Spec, grails will not find any tests if you forget this.
This is an example:
import grails.plugins.rest.client.RestBuilder
import spock.lang.Specification
class AuthenticationSpec extends Specification {
String baseUrl = "http://localhost:8080/grouply-backend"
void "test login wrong credentials"() {
given:
RestBuilder restBuilder = new RestBuilder()
when: "sending wrong credential"
def response = restBuilder.post("${baseUrl}/auth/login") {
json {
username = 'foo'
password = 'bar'
}
}
then: "authentication http error should happen"
response.status == 401
}
}
run tests with $ grails test-app functional:
I have just tried to use both functional testing plugin and webtest plugin with almost-current Grails 2.4.2 and I am sad to report that they are both borked. :(
Functional testing plugin has been practically abandoned for at least 9 months now. On December 2013 a critical bug that makes all of tests written using this plugin not working has been reported. There was no response from plugin developer regarding it up to the day I am writing this. And as this developer, Marc Palmer has switched to iOS development and consultancy in August 2014 I don't believe this bug will ever be resolved.
Webtest plugin has been last updated more than 3 years ago and it "requires Grails 1.2.RC2+". I run into ugly error of missing webtest.jar when running it and it looks like this plugin just haven't been updated to current Grails version. Also its syntax is not very Groovy-like and not nice.
Fortunately Geb integration for Grails plugin is supposed to work with current Grails versions. :) In fact in does only work with Grails 2.3.1+, as of writing these words has been last time updated in June 2014 and it's example tests project have been updated to Grails 2.4.3, release just a few days ago already, so it is very up-to-date. However I haven't used this project yet. Also looking at is's example code I am not sure it the best choice for RESTful API testing - it's more of a GUI web application testing tool..
Although is probably not very "grails style" i guess it should be possible to start up the whole stack with the spring context and run integration rest tests using apache HttpClient.

Grails Quartz Plugin Freezes on the 8th execution

Environment: Grails 2.0.3, Quartz plugin 1.0-RC2
I have a simple quartz job that reads a value from the database. On the 8th execution, the Job freezes while reading from the database. There is also a web page that retrieves the value from the DB. Once the Job gets into the waiting state, attempting to read the value through the web page also freezes.
Environment: Grails 2.2.0, Quartz plugin 1.0-RC5
I ran into the same problem using quartz-1.0-RC5.
As a workaround I replaced the SessionBinderJobListener class with the one from quartz-0.4.2 (changed only the package to the new one) and the job runs again without any problem. So it looks like the persistenceInterceptor bean does not close the connections or return them to the pool. Maybe there is a problem in org.codehaus.groovy.grails.orm.hibernate.support.HibernatePersistenceContextInterceptor with flush and destroy.
If org.quartz.threadPool.threadCount is much less than maxActive in dataSource properties, the problem does not appear (perhaps each job thread already got its connection) or it will only take longer.
The default size of the datasource connection pool is 8, so you're probably not properly closing the connections to return them to the pool.
I'm seeing the same thing with Quartz plugin version 1.0.1. On the 8th execution both the Job and Tomcat workers freeze. Used withSession and called Hibernate session.disconnect() in the finally {} block of the job. That did the trick.
def execute() {
def hsession
try {
DomainObject.withSession { ses ->
hsession = ses
....
}
} catch(Exception e) {
//log it etc.
} finally {
hsession?.disconnect()
}
}

Resources