Skip to content

Commit

Permalink
Merge pull request kagkarlsson#63 from evenh/spring-boot-support
Browse files Browse the repository at this point in the history
Spring boot support
  • Loading branch information
kagkarlsson authored Aug 7, 2019
2 parents 6dd7506 + 8d7c24b commit 2d2a592
Show file tree
Hide file tree
Showing 128 changed files with 1,753 additions and 179 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8

[*.java]
indent_style = space
indent_size = 4
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist: trusty
sudo: false
cache:
directories:
Expand Down
83 changes: 82 additions & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,106 @@ Licensed under Apache 2 - http://www.apache.org/licenses/LICENSE-2.0.html

This software includes third party software subject to the following licenses:

AntLR Parser Generator under BSD License
Apache Commons Codec under Apache License, Version 2.0
Apache Commons Compress under Apache License, Version 2.0
Apache Commons IO under Apache License, Version 2.0
Apache Commons Lang under Apache License, Version 2.0
Apache Log4j API under Apache License, Version 2.0
Apache Log4j to SLF4J Adapter under Apache License, Version 2.0
ASM based accessors helper used by json-smart under The Apache Software License, Version 2.0
ASM Core under BSD
AspectJ weaver under Eclipse Public License - v 1.0
AssertJ fluent assertions under Apache License, Version 2.0
Bean Validation API under Apache License 2.0
Byte Buddy (without dependencies) under Apache License, Version 2.0
Byte Buddy Java agent under Apache License, Version 2.0
ClassMate under The Apache Software License, Version 2.0
cron-utils under Apache 2.0
Db-scheduler under The Apache Software License, Version 2.0
db-scheduler: Core under The Apache Software License, Version 2.0
db-scheduler: Examples under The Apache Software License, Version 2.0
db-scheduler: Examples: Spring Boot under The Apache Software License, Version 2.0
db-scheduler: Parent under The Apache Software License, Version 2.0
db-scheduler: Spring Boot Starter under The Apache Software License, Version 2.0
dom4j under BSD 3-clause New License
Guava: Google Core Libraries for Java under The Apache Software License, Version 2.0
Hamcrest Core under New BSD License
Hamcrest library under New BSD License
HdrHistogram under Public Domain, per Creative Commons CC0
Hibernate Commons Annotations under GNU Lesser General Public License v2.1 or later
Hibernate ORM - hibernate-core under GNU Library General Public License v2.1 or later
Hibernate Validator Engine under Apache License 2.0
HikariCP under The Apache Software License, Version 2.0
HyperSQL Database under HSQLDB License, a BSD open source license
Jackson datatype: jdk8 under The Apache Software License, Version 2.0
Jackson datatype: JSR310 under The Apache Software License, Version 2.0
Jackson-annotations under The Apache Software License, Version 2.0
Jackson-core under The Apache Software License, Version 2.0
jackson-databind under The Apache Software License, Version 2.0
Jackson-module-parameter-names under The Apache Software License, Version 2.0
Java Annotation Indexer under Apache License, Version 2.0
java-8-matchers under MIT License
JavaBeans Activation Framework API jar under CDDL/GPLv2+CE
Javassist under MPL 1.1 or LGPL 2.1 or Apache License 2.0
javax.annotation API under CDDL + GPLv2 with classpath exception
javax.persistence-api under Eclipse Public License v1.0 or Eclipse Distribution License v. 1.0
javax.transaction API under CDDL + GPLv2 with classpath exception
jaxb-api under CDDL 1.1 or GPL2 w/ CPE
JBoss Logging 3 under Apache License, version 2.0
JCL 1.2 implemented over SLF4J under MIT License
JSON library from Android SDK under Apache License 2.0
JSON Small and Fast Parser under The Apache Software License, Version 2.0
JSONassert under The Apache Software License, Version 2.0
JUL to SLF4J bridge under MIT License
JUnit under Eclipse Public License 1.0
LatencyUtils under Public Domain, per Creative Commons CC0
Logback Classic Module under Eclipse Public License - v 1.0 or GNU Lesser General Public License
Logback Core Module under Eclipse Public License - v 1.0 or GNU Lesser General Public License
Micro JDBC under The Apache Software License, Version 2.0
micrometer-core under The Apache Software License, Version 2.0
mockito-core under The MIT License
Objenesis under Apache 2
org.xmlunit:xmlunit-core under The Apache Software License, Version 2.0
otj-pg-embedded under Apache License, Version 2.0
PostgreSQL JDBC Driver - JDBC 4.2 under The PostgreSQL License
project ':json-path' under The Apache Software License, Version 2.0
SLF4J API Module under MIT License
SLF4J Simple Binding under MIT License
SnakeYAML under Apache License, Version 2.0
Spring AOP under Apache License, Version 2.0
Spring Aspects under Apache License, Version 2.0
Spring Beans under Apache License, Version 2.0
Spring Boot under Apache License, Version 2.0
Spring Boot Actuator under Apache License, Version 2.0
Spring Boot Actuator AutoConfigure under Apache License, Version 2.0
Spring Boot Actuator Starter under Apache License, Version 2.0
Spring Boot AOP Starter under Apache License, Version 2.0
Spring Boot AutoConfigure under Apache License, Version 2.0
Spring Boot Data JPA Starter under Apache License, Version 2.0
Spring Boot JDBC Starter under Apache License, Version 2.0
Spring Boot Json Starter under Apache License, Version 2.0
Spring Boot Logging Starter under Apache License, Version 2.0
Spring Boot Starter under Apache License, Version 2.0
Spring Boot Test under Apache License, Version 2.0
Spring Boot Test Auto-Configure under Apache License, Version 2.0
Spring Boot Test Starter under Apache License, Version 2.0
Spring Boot Tomcat Starter under Apache License, Version 2.0
Spring Boot Web Starter under Apache License, Version 2.0
Spring Commons Logging Bridge under Apache License, Version 2.0
Spring Context under Apache License, Version 2.0
Spring Core under Apache License, Version 2.0
Spring Data Core under Apache License, Version 2.0
Spring Data JPA under Apache License, Version 2.0
Spring Expression Language (SpEL) under Apache License, Version 2.0
Spring JDBC under Apache License, Version 2.0
Spring Object/Relational Mapping under Apache License, Version 2.0
Spring TestContext Framework under Apache License, Version 2.0
Spring Transaction under Apache License, Version 2.0
Spring Web under Apache License, Version 2.0
Spring Web MVC under Apache License, Version 2.0
tomcat-embed-core under Apache License, Version 2.0
tomcat-embed-el under Apache License, Version 2.0
tomcat-embed-websocket under Apache License, Version 2.0
XZ for Java under Public Domain


42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final Scheduler scheduler = Scheduler
scheduler.start();
```

For more examples, continue reading. For details on the inner workings, see [How it works](#how-it-works).
For more examples, continue reading. For details on the inner workings, see [How it works](#how-it-works). If you have a Spring Boot application, have a look at [Spring Boot Usage](#spring-boot-usage).

## Examples

Expand Down Expand Up @@ -164,6 +164,46 @@ The library contains a number of Schedule-implementations for recurring tasks. S
| `.cron(String)` | Spring-style cron-expression. |


## Spring Boot usage

For Spring Boot applications, there is a starter `db-scheduler-spring-boot-starter` making the scheduler-wiring very simple. (See [full example project](https://github.com/kagkarlsson/db-scheduler/tree/master/examples/spring-boot-example)).

### Prerequisites

- An existing Spring Boot application
- A working `DataSource` with schema initialized. (In the example HSQLDB is used and schema is automatically applied.)

### Getting started

1. Add the following Maven dependency
```xml
<dependency>
<groupId>com.github.kagkarlsson</groupId>
<artifactId>db-scheduler-spring-boot-starter</artifactId>
<version>5.3</version> <!-- Look up the current version -->
</dependency>
```
**NOTE**: This includes the db-scheduler dependency itself.
2. In your configuration, expose your `Task`'s as Spring beans. If they are recurring, they will automatically be picked up and started.
3. Run the app.

### Configuration options

Configuration is mainly done via `application.properties`. Configuration of scheduler-name, serializer and executor-service is done by adding a bean of type `DbSchedulerCustomizer` to your Spring context.

```
# application.properties example showing default values

db-scheduler.enabled=true
db-scheduler.heartbeat-interval=5m
db-scheduler.polling-interval=30s
db-scheduler.polling-limit=
db-scheduler.table-name=scheduled_tasks
db-scheduler.immediate-execution-enabled=false
db-scheduler.scheduler-name=
db-scheduler.threads=10
```
## How it works
Expand Down
71 changes: 71 additions & 0 deletions db-scheduler-boot-starter/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
Db-scheduler

Copyright 2015 Gustav Karlsson. All Rights Reserved.

This product includes software developed by Gustav Karlsson.
Licensed under Apache 2 - http://www.apache.org/licenses/LICENSE-2.0.html


This software includes third party software subject to the following licenses:

Apache Log4j API under Apache License, Version 2.0
Apache Log4j to SLF4J Adapter under Apache License, Version 2.0
ASM based accessors helper used by json-smart under The Apache Software License, Version 2.0
ASM Core under BSD
AssertJ fluent assertions under Apache License, Version 2.0
Bean Validation API under Apache License 2.0
Byte Buddy (without dependencies) under Apache License, Version 2.0
Byte Buddy Java agent under Apache License, Version 2.0
ClassMate under The Apache Software License, Version 2.0
cron-utils under Apache 2.0
db-scheduler: Core under The Apache Software License, Version 2.0
db-scheduler: Spring Boot Starter under The Apache Software License, Version 2.0
Guava: Google Core Libraries for Java under The Apache Software License, Version 2.0
Hamcrest Core under New BSD License
Hamcrest library under New BSD License
Hibernate Validator Engine under Apache License 2.0
HikariCP under The Apache Software License, Version 2.0
HyperSQL Database under HSQLDB License, a BSD open source license
Jackson datatype: JSR310 under The Apache Software License, Version 2.0
Jackson-annotations under The Apache Software License, Version 2.0
Jackson-core under The Apache Software License, Version 2.0
jackson-databind under The Apache Software License, Version 2.0
javax.annotation API under CDDL + GPLv2 with classpath exception
JBoss Logging 3 under Apache License, version 2.0
JSON library from Android SDK under Apache License 2.0
JSON Small and Fast Parser under The Apache Software License, Version 2.0
JSONassert under The Apache Software License, Version 2.0
JUL to SLF4J bridge under MIT License
JUnit under Eclipse Public License 1.0
Logback Classic Module under Eclipse Public License - v 1.0 or GNU Lesser General Public License
Logback Core Module under Eclipse Public License - v 1.0 or GNU Lesser General Public License
Micro JDBC under The Apache Software License, Version 2.0
mockito-core under The MIT License
Objenesis under Apache 2
org.xmlunit:xmlunit-core under The Apache Software License, Version 2.0
project ':json-path' under The Apache Software License, Version 2.0
SLF4J API Module under MIT License
SnakeYAML under Apache License, Version 2.0
Spring AOP under Apache License, Version 2.0
Spring Beans under Apache License, Version 2.0
Spring Boot under Apache License, Version 2.0
Spring Boot Actuator under Apache License, Version 2.0
Spring Boot Actuator AutoConfigure under Apache License, Version 2.0
Spring Boot Auto-Configure Annotation Processor under Apache License, Version 2.0
Spring Boot AutoConfigure under Apache License, Version 2.0
Spring Boot Configuration Processor under Apache License, Version 2.0
Spring Boot JDBC Starter under Apache License, Version 2.0
Spring Boot Logging Starter under Apache License, Version 2.0
Spring Boot Starter under Apache License, Version 2.0
Spring Boot Test under Apache License, Version 2.0
Spring Boot Test Auto-Configure under Apache License, Version 2.0
Spring Boot Test Starter under Apache License, Version 2.0
Spring Commons Logging Bridge under Apache License, Version 2.0
Spring Context under Apache License, Version 2.0
Spring Core under Apache License, Version 2.0
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


102 changes: 102 additions & 0 deletions db-scheduler-boot-starter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>db-scheduler-parent</artifactId>
<groupId>com.github.kagkarlsson</groupId>
<version>5.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>db-scheduler-spring-boot-starter</artifactId>
<name>db-scheduler: Spring Boot Starter</name>
<description>A starter for Spring Boot that will configure db-scheduler</description>

<properties>
<license.dir>${project.parent.basedir}/.license</license.dir>
</properties>

<dependencies>
<!-- The library itself -->
<dependency>
<groupId>com.github.kagkarlsson</groupId>
<artifactId>db-scheduler</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
<optional>true</optional>
</dependency>

<!-- Validation -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<scope>provided</scope>
</dependency>

<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.kagkarlsson.scheduler.boot.actuator;

import com.github.kagkarlsson.scheduler.Scheduler;
import com.github.kagkarlsson.scheduler.SchedulerState;
import java.util.Objects;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;

public class DbSchedulerHealthIndicator implements HealthIndicator {
private final SchedulerState state;

public DbSchedulerHealthIndicator(Scheduler scheduler) {
this.state = Objects.requireNonNull(scheduler).getSchedulerState();
}

@Override
public Health health() {
if (state.isStarted() && !state.isShuttingDown()) {
return Health.up()
.withDetail("state", "started")
.build();
} else if (state.isStarted() && state.isShuttingDown()) {
return Health.outOfService()
.withDetail("state", "shutting_down")
.build();
} else if (!state.isStarted() && !state.isShuttingDown()) {
return Health.down()
.withDetail("state", "not_started")
.build();
} else {
return Health.down().build();
}
}
}
Loading

0 comments on commit 2d2a592

Please sign in to comment.