Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GRAILS-8921: Support for Scheduling via Spring's @Scheduled annotation #2216

Closed
graemerocher opened this issue Mar 15, 2012 · 20 comments
Closed
Labels
type: enhancement New feature or request type: minor

Comments

@graemerocher
Copy link
Member

Original Reporter: sothmann
Environment: Not Specified
Version: Not Specified
Migrated From: http://jira.grails.org/browse/GRAILS-8921

I'd like to see support for Spring's @scheduled annotation in Grails services.
See http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/scheduling.html#scheduling-annotation-support-scheduled

Currently Grails 2.0.1 seems to not support @scheduled annotation in services.
If this annotation would be supported, there would be no need to use a separate plugin for this (quartz plugin) and scheduling would become much more simple in Grails.

@graemerocher
Copy link
Member Author

cdeszaq said:
For advanced scheduling needs (using a Quartz cluster to run jobs, for example) a plugin would still be needed, but supporting the @scheduled annotation would likely cover 90+% of use cases.

@graemerocher
Copy link
Member Author

graemerocher said:
We should make a call on this as well whether we should implement our own version of @async that uses transformations. Introducing proxying is not ideal when we have just gotten rid of the proxying happening with @transactional

@graemerocher
Copy link
Member Author

zyro said:
tried this again with 2.4.0.RC2 and now it seems its not working on services at all - no matter if static transactional = false or not... but its working as it should with "standard" src/groovy beans

@graemerocher
Copy link
Member Author

brownj said:
zyro, Please attach a sample which shows a simple example of standard beans working and services not working. That would be helpful.

@graemerocher
Copy link
Member Author

zyro said:
here u go. thanks, zyro

@graemerocher
Copy link
Member Author

brownj said:
Thanks.

@graemerocher graemerocher modified the milestones: grails-2.5.1, grails-3.1 May 27, 2015
@jeffscottbrown jeffscottbrown removed their assignment Oct 20, 2015
@graemerocher graemerocher removed this from the grails-3.1.0.RC2 milestone Jan 22, 2016
@slackboxster
Copy link

At my company, have been using @scheduled in a grails application that was running on 3.1.0.RC2. Recently it stopped working after attempting to upgrade to 3.1.9. Further investigation indicates that @scheduled stopped working in 3.1.7. I was considering creating an issue to get some feedback on the problem from a grails perspective, but this looks too closely related for a new issue.

I've dug through things a little and noticed that 3.1.7 includes an upgrade from Spring Boot 1.3.3 to 1.3.5. Somewhere in the Spring Boot 1.3.4 changes they updated to Spring Framework 4.2.6. That's about as far as I've gotten.

Using @scheduled does make scheduling tasks way simpler, so I'd like to see this supported.

@graemerocher
Copy link
Member Author

Are you using it on services? If yes then add lazyInit = false to the service

@slackboxster
Copy link

On services indeed. I will give that a try in a moment.

Side note, I tried creating a sample app , and neither with 3.1.6 nor 3.1.0.RC2 was I able to get @scheduled working out of the box. It would take a while to figure out what of the things we've done in our app makes the difference, but it appears there is something.

@slackboxster
Copy link

@graemerocher boolean lazyInit = false fixed it, running on 3.1.9. Thank you. :)

I added that answer to this stackoverflow, feel free to add the answer yourself and I'll delete mine (I don't want to steal your answer / rep unnecessarily).

@slackboxster
Copy link

slackboxster commented Jul 28, 2016

Before my comments, based on this issue I would have concluded @scheduled is not supported in Grails. Are we doing something weird to get that working? And is there something I could try / do to help move support for it forward?

@graemerocher
Copy link
Member Author

maybe a pull request to check whether @Scheduled is defined and if so default to non-lazy would be an improvement. Would have to be defined here 1752b1b#diff-2c5bac05d9f843cf54cde17bb95eb286R221

@slackboxster
Copy link

I was able to get the code written. However, I'm still having trouble creating a basic sample app that works with @scheduled, and our app that is using @scheduled in the service is giving me trouble that appears associated with switching from 3.1.x to 3.2.x.

Regardless I wanted to get the code out so that (a) I can learn and (b) you have something to work with.

@slackboxster
Copy link

nevermind. I got our app working with my dev grails on 3.2.0.BUILD-SNAPSHOT. But it appears I have to still hard code lazyInit = false -- so ignore that PR for now. Sorry about that.

@slackboxster
Copy link

My code is definitely running, but it appears that setting the bd.lazyInit does not actually cause lazyInit to happen.

@slackboxster
Copy link

slackboxster commented Jul 29, 2016

I was able to get things to work if my service had boolean lazyInit defined. It doesn't have to be initialized, just defined.
This was on both our grails app and on my sample app.

@snimavat
Copy link
Contributor

snimavat commented Jan 5, 2017

This is fixed in Spring 4.3 RC2 -- https://jira.spring.io/browse/SPR-12872

so should work without needing to add lazyInit = true with grails 3.3.x
Just add @EnableScheduling to Application class .

@graemerocher
Copy link
Member Author

Grails 3.2 also uses Spring 4.3

@tlefevre
Copy link
Contributor

I was just forced to use the "lazyInit" fix in a fresh grails 3.3.3 app. Spring version is 4.3.14.RELEASE.

@benrhine
Copy link
Contributor

benrhine commented Apr 6, 2018

We specifically published a guide on this earlier this year http://guides.grails.org/grails-scheduled/guide/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request type: minor
Projects
None yet
Development

No branches or pull requests

7 participants