Created
March 27, 2016 20:55
-
-
Save astray1988/d740fe7be2445ef79681 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Define Retry Function | |
| def withRetry[T](retries: Int = 5)(f: => Future[T]): Future[T] = f.recoverWith { | |
| case t:Throwable if (retries > 0) => withRetry(retries - 1)(f) | |
| } | |
| // Use thrid party lib | |
| libraryDependencies += "net.databinder.dispatch" % "dispatch-core_2.10" % "0.11.2" | |
| import dispatch._, Defaults._ | |
| //Use retry mechanism if network fails, try 5 seconds after network failure, maximum try 4 times | |
| retry.Backoff(max = 5, delay = 5.seconds)(() => MockPriceService.price(prodInfo.productId)).map { | |
| case None => NotFound("The price of this product is not exist") | |
| case Some(prodPrice) => | |
| Ok(views.html.productDetail(prodInfo, prodPrice)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment