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

Adds db connectivity check to status #150

Merged
merged 4 commits into from
Aug 23, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions core/src/main/scala/com/criteo/cuttle/App.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,16 @@ private[cuttle] case class App[S <: Scheduling](project: CuttleProject[S], execu
val publicApi: PartialService = {

case GET at url"/api/status" =>
Ok(
Json.obj(
"project" -> project.name.asJson,
"version" -> Option(project.version).filterNot(_.isEmpty).asJson,
"status" -> "ok".asJson
))
executor.healthCheck
.fold(
t => InternalServerError(t.getMessage()),
Copy link
Contributor

Choose a reason for hiding this comment

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

why not returning the same JSON structure in case of error?

_ => Ok(
Json.obj(
"project" -> project.name.asJson,
"version" -> Option(project.version).filterNot(_.isEmpty).asJson,
"status" -> "ok".asJson
))
)

case GET at url"/api/statistics?events=$events&jobs=$jobs" =>
val filteredJobs = Try(jobs.split(",").toSeq.filter(_.nonEmpty)).toOption
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/scala/com/criteo/cuttle/Database.scala
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,10 @@ private[cuttle] trait Queries {
new ExecutionStat(startTime, endTime, durationSeconds, waitingSeconds, status)
})
}

val healthCheck : ConnectionIO[Boolean] =
sql"""select 1 from dual"""
.query[Boolean]
.unique
}

6 changes: 6 additions & 0 deletions core/src/main/scala/com/criteo/cuttle/Executor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,10 @@ class Executor[S <: Scheduling] private[cuttle] (
.foreach({ case (e, _) => e.updateWaitingTime(intervalSeconds) })
}
}

private[cuttle] def healthCheck(): Either[Throwable, Boolean] = {
import fs2.interop.cats._

queries.healthCheck.attempt.transact(xa).unsafePerformIO
}
}