-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow custom cron expression for cleanup task #616
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
Comments
Thanks for the report! I'm not sure it is quite that simple since you need fail-over. What happens when one of the server instances crashes? Nothing is cleaning up expired sessions then. |
Ahh, very good point! Hadn't thought about what would happen if the server in charge of cleaning up sessions goes down. |
@rwinch We could expose the cron expression used by |
@ajthom90 Having in mind this situation can be viewed as an edge case, perhaps it's not worth the complexity it would add to the configuration support. IMO it falls in the same category as custom SQL queries which will be introduced as a part of #613. Setting custom SQL will require users to manually declare That being said, you could easily work around your problem with a custom public class CustomJdbcOperationsSessionRepository
extends JdbcOperationsSessionRepository {
public CustomJdbcOperationsSessionRepository(JdbcOperations jdbcOperations,
PlatformTransactionManager transactionManager) {
super(jdbcOperations, transactionManager);
}
@Override
@Scheduled(cron = "desired cron expression")
public void cleanUpExpiredSessions() {
super.cleanUpExpiredSessions();
}
} When registering the custom repository, make sure the bean is named @EnableJdbcHttpSession
public class HttpSessionConfig {
@Bean
public CustomJdbcOperationsSessionRepository sessionRepository(
@Qualifier("springSessionJdbcOperations") JdbcOperations jdbcOperations,
PlatformTransactionManager transactionManager) {
return new CustomJdbcOperationsSessionRepository(
jdbcOperations, transactionManager);
}
} |
Thanks @rwinch!! That was much simpler than I proposed :) Thanks for your help!!! |
@ajthom90 Thanks for the report and helping to make Spring Session better :) |
@rwinch Great solution to this problem, I like it! 👍 |
APPLICATION FAILED TO START Description: Parameter 0 of method sessionRepository in com.example.AportalApplication required a bean of type 'org.springframework.jdbc.core.JdbcOperations' that could not be found. Action: Consider defining a bean of type 'org.springframework.jdbc.core.JdbcOperations' in your configuration. How to solve this? |
@littlehome-eugene Commeting on closed issue isn't the best way to report problem. Please open a new issue and provide as much information (related configurations, versions of Spring Session, Boot, etc. you use) as possible to help us diagnose the problem. |
Uh oh!
There was an error while loading. Please reload this page.
Updated Description
Use
spring.session.cleanup.cron.expression
property to override the cleanup task cron expression.Original Description
I have a Spring Boot application using Spring Session 1.2.1.RELEASE. I have two servers running the application behind a load balancer, and the session information is stored in MySQL databases that use master-master replication. When the Scheduled task runs to delete sessions (JdbcOperationsSessionRepository.cleanUpExpiredSessions()), it runs on both web servers, which then tries to run on both databases and the replication runs into issues.
It would be nice to be able to set a system property so the scheduled cleanUpExpiredSessions() method will only run on one database, and MySQL replication will take care of the rest behind the scenes.
The text was updated successfully, but these errors were encountered: