Skip to content

Instantly share code, notes, and snippets.

@spockz
Created February 3, 2016 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spockz/8aad66e714fd6e628c4f to your computer and use it in GitHub Desktop.
Save spockz/8aad66e714fd6e628c4f to your computer and use it in GitHub Desktop.
/**
* Wraps two services in a new service which checks whether the {{primaryService}} is
* available and uses it when it is available. Otherwise, it will use the {{backupService}}.
*/
class FailoveringService[Req, Rep](primaryService: Service[Req, Rep],
backupService: Service[Req, Rep])
extends Service[Req, Rep] {
override def apply(request: Req) =
(if (primaryService.isAvailable) primaryService else backupService) (request)
override def status = Status.best(primaryService.status, backupService.status)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment