package com.github.arteam.jdbi3;

import com.codahale.metrics.health.HealthCheck;
import io.dropwizard.db.TimeBoundHealthCheck;
import io.dropwizard.util.Duration;
import org.jdbi.v3.core.Handle;
import org.jdbi.v3.core.Jdbi;

import java.util.concurrent.ExecutorService;

/**
 * @author Artem Prigoda
 * @since 28.07.16
 */
public class JdbiHealthCheck extends HealthCheck {

    private final Jdbi jdbi;
    private final String validationQuery;
    private final TimeBoundHealthCheck timeBoundHealthCheck;

    public JdbiHealthCheck(ExecutorService executorService, Duration duration, Jdbi dbi, String validationQuery) {
        this.jdbi = dbi;
        this.validationQuery = validationQuery;
        this.timeBoundHealthCheck = new TimeBoundHealthCheck(executorService, duration);
    }

    @Override
    protected Result check() throws Exception {
        return timeBoundHealthCheck.check(() -> {
            try (Handle handle = jdbi.open()) {
                handle.execute(validationQuery);
                return Result.healthy();
            }
        });
    }
}

@@ -218,16 +218,73 @@
 re.Jdbi;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aimport
@@ -425,16 +425,102 @@
 hCheck %7B
+%0A    private static final Logger log = LoggerFactory.getLogger(JdbiHealthCheck.class);
 %0A%0A    pr
@@ -1180,16 +1180,215 @@
 lthy();%0A
+            %7D catch (Exception e) %7B%0A                log.error(%22jDBI Healthcheck failed. validation-query=%7B%7D%22, validationQuery, e);%0A                return Result.unhealthy(%22Validation query failed%22);%0A
         

Add error handling and logging to healthcheck