Add a basic health check and make sure `./gradlew run` actually stands up the server

This commit is contained in:
R. Tyler Croy 2015-05-29 18:50:44 -07:00
parent 4228871e19
commit 2cb37364c0
7 changed files with 42 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
build/
.gradle/
*.sw*
.idea/

View File

@ -4,6 +4,9 @@ plugins {
id 'codenarc'
}
description = 'Offtopic is for watching Kafka topics'
mainClassName = 'offtopic.OfftopicApp'
repositories {
jcenter()
}
@ -29,3 +32,7 @@ test {
codenarc {
configFile = file("${projectDir}/gradle/codenarc.xml")
}
run {
args 'server', 'offtopic.example.yml'
}

View File

@ -1,3 +1,8 @@
// Project settings
version=0.3.0
group=com.github.rtyler
// Build settings
dropwizardVersion=0.8.1
groovyVersion=2.4.3

2
offtopic.example.yml Normal file
View File

@ -0,0 +1,2 @@
logging:
level: INFO

View File

@ -4,12 +4,15 @@ import io.dropwizard.Application
import io.dropwizard.setup.Bootstrap
import io.dropwizard.setup.Environment
import groovy.transform.TypeChecked
import org.slf4j.Logger
import org.slf4j.LoggerFactory
/**
* Primary application instance for Dropwizard
*/
@TypeChecked
class OfftopicApp extends Application<OfftopicConfig> {
/**
* Primary logger instance for the app
@ -28,6 +31,8 @@ class OfftopicApp extends Application<OfftopicConfig> {
@Override
void run(OfftopicConfig configuration, Environment environment) throws Exception {
this.logger.info("Starting the Offtopic application")
environment.healthChecks().register('sanity', new offtopic.health.BasicHealth())
}
@Override

View File

@ -0,0 +1,14 @@
package offtopic.health
import com.codahale.metrics.health.HealthCheck
import com.codahale.metrics.health.HealthCheck.Result
/**
* A basic healthcheck to ensure that the application is at least executing properly
*/
class BasicHealth extends HealthCheck {
@Override
protected Result check() {
return Result.healthy()
}
}

View File

@ -0,0 +1,8 @@
package offtopic.resources
/**
*
*/
@SuppressWarnings('EmptyClass')
class MainResource {
}