Skip to content

Support Kotlin suspending functions with @Scheduled #28515

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

Closed

Conversation

wine-area
Copy link
Contributor

This commit provides a scheduled task to support coroutines, but I'm not sure how to do a full unit test

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 24, 2022
@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement theme: kotlin An issue related to Kotlin support labels May 24, 2022
@sbrannen sbrannen changed the title add support for suspend @Scheduled Support Kotlin suspending functions with @Scheduled May 24, 2022
@poutsma poutsma self-assigned this May 30, 2022
@sdeleuze sdeleuze self-assigned this Feb 8, 2023
@sdeleuze sdeleuze removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 8, 2023
@sdeleuze sdeleuze added this to the 6.1.0-M1 milestone Feb 8, 2023
@sdeleuze
Copy link
Contributor

Thanks for this contribution. After reviewing this PR with @simonbasle, I think that's better to reimplement it as a commit part of #29924. So I will close this PR, and you can track #29924 for the availability of Coroutines support for @Scheduled.

@sdeleuze sdeleuze closed this Feb 14, 2023
@sdeleuze sdeleuze added the status: duplicate A duplicate of another issue label Feb 14, 2023
@jhoeller jhoeller removed this from the 6.1.0-M1 milestone Feb 14, 2023
simonbasle added a commit to simonbasle/spring-framework that referenced this pull request May 5, 2023
bclozel pushed a commit that referenced this pull request Jun 5, 2023
This commit adds support for `@Scheduled` annotation on reactive
methods and Kotlin suspending functions.

Reactive methods are methods that return a `Publisher` or a subclass
of `Publisher`. The `ReactiveAdapterRegistry` is used to support many
implementations, such as `Flux`, `Mono`, `Flow`, `Single`, etc.
Methods should not take any argument and published values will be
ignored, as they are already with synchronous support.

This is implemented in `ScheduledAnnotationReactiveSupport`, which
"converts" Publishers to `Runnable`. This strategy keeps track of
active Subscriptions in the `ScheduledAnnotationBeanPostProcessor`,
in order to cancel them all in case of shutdown.
The existing scheduling support for tasks is reused, aligning the
triggering behavior with the existing support: cron, fixedDelay and
fixedRate are all supported strategies.

If the `Publisher` errors, the exception is logged at warn level and
otherwise ignored. As a result new `Runnable` instances will be
created for each execution and scheduling will continue.
The only difference with synchronous support is that error signals
will not be thrown by those `Runnable` tasks and will not be made
available to the `org.springframework.util.ErrorHandler` contract.
This is due to the asynchronous and lazy nature of Publishers.

Closes gh-23533
Closes gh-28515
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue theme: kotlin An issue related to Kotlin support type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants