micronaut-core
micronaut-core copied to clipboard
@Scheduled `suspend fun` never runs
Expected Behavior
@Scheduled(fixedDelay = "1s")
suspend fun suspendTest() {
println("suspend Hello World")
}
Expected is that "suspend Hello World" prints once per second
Actual Behaviour
Nothing prints
Steps To Reproduce
- start a project with micronaut-core in kotlin
- make a suspending function inside a singleton
- annotate it with
@Scheduled
- run and observe behavior
Environment Information
jdk 11 macos 12.3
Example Application
https://github.com/rawilder/scheduled-kotlin
Version
3.4.2
@rawilder What is the point in making it a suspend function?
Clean usage with other suspending functions. If I wanted to schedule once a day to refresh data from a third party API, that API client is likely a publisher or suspending function. Rather than hard blocking inside the scheduled function (runBlocking
or <ReactorType>.block()
), it'd be nice to be able to tie together the functionality cleanly. runBlocking
has given me a lot of grief so I try to avoid it when possible.
This is because the scheduled processor checks if the method has 0 arguments. In the case of a suspend function being called from Java, it takes a continuation argument
It doesn't make much sense to have it, we can't do anything special to block it, and probably an error message should be thrown in that case.
perhaps this should be a compilation error
So is the recommended solution to wrap it with runBlocking {}
?
I think this should be handled at the framework level, otherwise anyone who executes methods will likely run into this issue and will have to handle it. For ExecutableMethods we should pre-load the continuation
This is what I tried. Since the runner checks for 0 arguments, I added an else case to check for one argument of the continuation type but I got stuck trying to figure out what to pass in and where to get it from.
bump - happening to us too