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

Spring boot support #63

Merged
merged 24 commits into from
Aug 7, 2019
Merged

Conversation

evenh
Copy link
Contributor

@evenh evenh commented Jul 23, 2019

This PR addresses #55 and provides an initial implementation for Spring Boot integration.

@kagkarlsson
Copy link
Owner

Awesome, thanks! Will have a look! :)

@evenh
Copy link
Contributor Author

evenh commented Jul 23, 2019 via email

Copy link
Owner

@kagkarlsson kagkarlsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, though probably will need a second scan of things :)

Would be neat with some short example Main showing a minimal example, ala for example https://github.com/kagkarlsson/db-scheduler/blob/master/src/test/java/com/github/kagkarlsson/scheduler/example/CronMain.java

.editorconfig Show resolved Hide resolved
Spring Expression Language (SpEL) under Apache License, Version 2.0
Spring JDBC under Apache License, Version 2.0
Spring TestContext Framework under Apache License, Version 2.0
Spring Transaction under Apache License, Version 2.0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will check this later..

@kagkarlsson
Copy link
Owner

Hmm, I think we are missing the startTasks(...) aspect for kicking off initial execution for recurring tasks, see https://github.com/kagkarlsson/db-scheduler/blob/master/src/test/java/com/github/kagkarlsson/scheduler/example/TasksMain.java#L41

Tasks that also implement OnStartup should be added to the builder via startTasks(...) method

@evenh
Copy link
Contributor Author

evenh commented Jul 24, 2019

I've implemented the startTasks invocation in the builder, where I've filtered out tasks which do and do not implement OnStartup.

As for the examples, should they be separate "real" Spring Boot projects? I was thinking something like (Maven hierarchy):

| db-scheduler
| db-scheduler-boot-starter
| examples
|  --> spring-boot-example
|  --> vanilla-java-example?
|  --> other-example?

The benefit of this approach is breakage of the examples if the library/integrations change :-)

log.info("Creating DB Scheduler using tasks from Spring context: {}", configuredTasks);

if (existingDataSource instanceof TransactionAwareDataSourceProxy) {
log.info("Using a transaction aware DataSource");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really necessary information to give? I guess the else block info makes more sense than this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not worthy of an info but a debug might be handy?

if (existingDataSource instanceof TransactionAwareDataSourceProxy) {
log.info("Using a transaction aware DataSource");
} else {
log.info("The configured DataSource is not transaction aware: '{}'. Operations such as schedule, reschedule and cancel will have effect regardless of spanning transactions.", existingDataSource);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log statement is a bit confusing. What is the purpose of this?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there cases where a Spring-user might send in a datasource is not transaction-aware by mistake?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cash1981: I thought that information whether one uses an instance of TransactionAwareDataSourceProxy would be useful information, see the docs.

However, I can't seem to get Spring Boot's configuration to provide me with a TransactionAwareDataSourceProxy out of the box (using JPA or JDBC starter, @EnableTransactionManagement on/off and using a local PostgreSQL db).

@cash1981
Copy link

Perhaps also update the documentation on how to add db-scheduler using Spring and this PR?

@evenh
Copy link
Contributor Author

evenh commented Jul 29, 2019

Absolutely @cash1981! As pointed out in this comment, we should consider adding some examples and link to those as well.

@kagkarlsson
Copy link
Owner

@evenh Yeah for spring-boot I think it makes sense to have an examples-directory with a full project that is part of the build. We can link to it from the documentation. If necessary, code can be copied to the markdown-doc. Maybe a separate markdown-page for usage in spring-boot which we link to.

If you could create an example project @evenh , I can update the doc :)

@evenh
Copy link
Contributor Author

evenh commented Jul 31, 2019

Fixed @kagkarlsson :)

@kagkarlsson
Copy link
Owner

Ran the example and shutdown seem to be working as exepected @cash1981

@kagkarlsson
Copy link
Owner

I think we need to wrap the datasource in a TransactionAwareDataSourceProxy if it is not already

@kagkarlsson
Copy link
Owner

Enabled maven-dependency-plugin:

[WARNING] Used undeclared dependencies found:
[WARNING]    org.springframework.boot:spring-boot-test:jar:2.1.6.RELEASE:test
[WARNING]    org.assertj:assertj-core:jar:3.11.1:test
[WARNING]    org.springframework.boot:spring-boot-autoconfigure:jar:2.1.6.RELEASE:compile
[WARNING]    org.springframework.boot:spring-boot-actuator:jar:2.1.6.RELEASE:compile
[WARNING]    org.springframework.boot:spring-boot:jar:2.1.6.RELEASE:compile
[WARNING]    junit:junit:jar:4.12:test
[WARNING]    org.slf4j:slf4j-api:jar:1.7.26:compile
[WARNING]    org.springframework:spring-context:jar:5.1.8.RELEASE:compile
[WARNING] Unused declared dependencies found:
[WARNING]    org.springframework.boot:spring-boot-configuration-processor:jar:2.1.6.RELEASE:compile
[WARNING]    org.springframework.boot:spring-boot-starter:jar:2.1.6.RELEASE:compile
[WARNING]    org.springframework.boot:spring-boot-autoconfigure-processor:jar:2.1.6.RELEASE:compile```

Will see if I can fix a couple.. 

@kagkarlsson
Copy link
Owner

Merging this PR. Further improvements can be suggested as separate issues.

@kagkarlsson kagkarlsson merged commit ca30dd7 into kagkarlsson:master Aug 7, 2019
evenh pushed a commit to evenh/db-scheduler that referenced this pull request Oct 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants