Skip to content

Commit

Permalink
Update shutdown endpoint (#237)
Browse files Browse the repository at this point in the history
- the user should explicitly use hard or gracePeriodSeconds as query parameters
  • Loading branch information
jedirandy authored Feb 27, 2018
1 parent eeeab3f commit ce09a82
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions core/src/main/scala/com/criteo/cuttle/App.scala
Original file line number Diff line number Diff line change
Expand Up @@ -369,24 +369,26 @@ private[cuttle] case class App[S <: Scheduling](project: CuttleProject[S], execu
IO.pure(Ok)
}

case GET at url"/api/shutdown?gracePeriodSeconds=$gracePeriodSeconds" => { implicit user =>
case req@GET at url"/api/shutdown" => { implicit user =>
import scala.concurrent.duration._

val gracePeriod: Try[Long] = gracePeriodSeconds match {
case "" => Success(300)
case p => Try(p.toLong)
}

gracePeriod match {
case Success(s) if s > 0 => {
executor.gracefulShutdown(Duration(s, SECONDS))
Ok
}
case Success(s) if s <= 0 => {
executor.hardShutdown()
Ok
}
case _ => BadRequest("gracePeriodSeconds should be an integer")
req.queryStringParameters.get("gracePeriodSeconds") match {
case Some(s) =>
Try(s.toLong) match {
case Success(s) if s > 0 =>
executor.gracefulShutdown(Duration(s, SECONDS))
Ok
case _ =>
BadRequest("gracePeriodSeconds should be a positive integer")
}
case None =>
req.queryStringParameters.get("hard") match {
case Some(_) =>
executor.hardShutdown()
Ok
case None =>
BadRequest("Either gracePeriodSeconds or hard should be specified as query parameter")
}
}
}
}
Expand Down

0 comments on commit ce09a82

Please sign in to comment.