Skip to content
Snippets Groups Projects
Commit f5567ae9 authored by Richard Alam's avatar Richard Alam
Browse files

- add health service

parent 52dbe43c
No related branches found
No related tags found
No related merge requests found
......@@ -5,23 +5,17 @@ import akka.http.scaladsl.model._
import akka.actor.ActorSystem
import akka.http.scaladsl.server.Directives._
import akka.stream.Materializer
import com.google.gson.Gson
import org.bigbluebutton.service.HealthzResponse
class ApiService()(implicit executor: ExecutionContext, as: ActorSystem, mat: Materializer) {
def routes =
path("hello") {
path("healthz") {
get {
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Say hello to akka-http</h1>"))
}
} ~
// Add a new route
pathPrefix("healthz") {
pathEndOrSingleSlash {
get {
complete {
"Hello World!"
}
}
}
val gson = new Gson()
val response = new HealthzResponse("ok", "fine")
complete(StatusCodes.ServiceUnavailable, HttpEntity(ContentTypes.`application/json`, gson.toJson(response)))
}
}
}
package org.bigbluebutton.service
import akka.actor.{Actor, ActorContext, ActorLogging, Props}
import akka.actor.ActorSystem
import akka.pattern.{ask}
import akka.util.Timeout
import scala.concurrent.duration._
import scala.util.Success
import scala.util.Failure
case class HealthzResponse(toFS: String, fromFS: String)
case class ToFSStatus(status: String)
case class FromFsStatus(status: String)
case object GetHealthStatus
class HealthzService() (implicit val context: ActorContext, system: ActorSystem) {
implicit def executionContext = system.dispatcher
val actorRef = context.actorOf(HealthzActor.props())
def getHealthz():String = {
val future = actorRef.ask(GetHealthStatus)(5 seconds)
var toReturn = ""
future onComplete {
case Success(result) =>
toReturn = "Success"
case Failure(failure) =>
toReturn = "Failed"
}
toReturn
}
}
object HealthzActor {
def props(): Props = Props(classOf[HealthzActor])
}
class HealthzActor extends Actor
with ActorLogging {
def receive = {
case msg: ToFSStatus => println(msg)
case msg: FromFsStatus => println(msg)
case GetHealthStatus => println("GetHealthStatus")
case _ => println("that was unexpected")
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment