1 /* 2 * Make.org Core API 3 * Copyright (C) 2018 Make.org 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU Affero General Public License as 7 * published by the Free Software Foundation, either version 3 of the 8 * License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Affero General Public License for more details. 14 * 15 * You should have received a copy of the GNU Affero General Public License 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package org.make.api.technical.healthcheck 21 22 import io.circe.{Encoder, Json} 23 import org.make.api.technical.healthcheck.HealthCheck.Status 24 25 import scala.concurrent.{ExecutionContext, Future} 26 27 trait HealthCheck { 28 29 val techno: String 30 31 def healthCheck()(implicit ctx: ExecutionContext): Future[Status] 32 } 33 34 object HealthCheck { 35 sealed trait Status extends Product with Serializable { 36 def message: String 37 } 38 39 object Status { 40 case object OK extends Status { 41 override val message: String = "OK" 42 } 43 final case class NOK(reason: Option[String] = None) extends Status { 44 override val message: String = reason.map(r => s"NOK: $r").getOrElse("NOK") 45 } 46 } 47 48 final case class HealthCheckResponse(service: String, message: String) 49 50 object HealthCheckResponse { 51 implicit val encoderSuccess: Encoder[HealthCheckResponse] = new Encoder[HealthCheckResponse] { 52 override def apply(response: HealthCheckResponse): Json = 53 Json.obj((response.service, Json.fromString(response.message))) 54 } 55 } 56 }
| Line | Stmt Id | Pos | Tree | Symbol | Tests | Code |
|---|---|---|---|---|---|---|
| 41 | 49921 | 1248 - 1252 | Literal | <nosymbol> | "OK" | |
| 44 | 41517 | 1369 - 1413 | Apply | scala.Option.getOrElse | NOK.this.reason.map[String](((r: String) => ("NOK: ".+(r): String))).getOrElse[String]("NOK") | |
| 51 | 44176 | 1594 - 1597 | Apply | org.make.api.technical.healthcheck.HealthCheck.HealthCheckResponse.$anon.<init> | new $anon() | |
| 53 | 50672 | 1745 - 1761 | Select | org.make.api.technical.healthcheck.HealthCheck.HealthCheckResponse.message | response.message | |
| 53 | 48051 | 1701 - 1764 | Apply | io.circe.Json.obj | io.circe.Json.obj(scala.Tuple2.apply[String, io.circe.Json](response.service, io.circe.Json.fromString(response.message))) | |
| 53 | 35568 | 1710 - 1763 | Apply | scala.Tuple2.apply | scala.Tuple2.apply[String, io.circe.Json](response.service, io.circe.Json.fromString(response.message)) | |
| 53 | 33941 | 1711 - 1727 | Select | org.make.api.technical.healthcheck.HealthCheck.HealthCheckResponse.service | response.service | |
| 53 | 43146 | 1729 - 1762 | Apply | io.circe.Json.fromString | io.circe.Json.fromString(response.message) |