You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ra...@apache.org on 2018/02/20 22:09:21 UTC

[incubator-openwhisk] branch master updated: Bump default retry timeout to 50 milliseconds. (#3311)

This is an automated email from the ASF dual-hosted git repository.

rabbah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git


The following commit(s) were added to refs/heads/master by this push:
     new e346318  Bump default retry timeout to 50 milliseconds. (#3311)
e346318 is described below

commit e346318ce649d93452159dc866a039c4f7eebbad
Author: Markus Thömmes <ma...@me.com>
AuthorDate: Tue Feb 20 23:09:17 2018 +0100

    Bump default retry timeout to 50 milliseconds. (#3311)
    
    The default retry timeout is fairly low today (1 millisecond). Rather than adjusting each value locally, we should use a more decent value to start with globally.
---
 .../scala/src/main/scala/whisk/utils/Retry.scala   | 25 +++++++---------------
 1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/common/scala/src/main/scala/whisk/utils/Retry.scala b/common/scala/src/main/scala/whisk/utils/Retry.scala
index 9a759dd..e5f7c22 100644
--- a/common/scala/src/main/scala/whisk/utils/Retry.scala
+++ b/common/scala/src/main/scala/whisk/utils/Retry.scala
@@ -17,12 +17,7 @@
 
 package whisk.utils
 
-import scala.concurrent.duration.Duration
-import scala.concurrent.duration.DurationInt
-import scala.util.Failure
-import scala.util.Success
-import scala.util.Try
-import scala.language.postfixOps
+import scala.concurrent.duration._
 
 object retry {
 
@@ -34,21 +29,17 @@ object retry {
    * @param N the maximum number of times to apply fn, must be >= 1
    * @param waitBeforeRetry an option specifying duration to wait before retrying method, will not wait if none given
    * @return the result of fn iff it is successful
-   * @throws exception from fn (or an illegal argument exception if N is < 1)
+   * @throws Throwable exception from fn (or an illegal argument exception if N is < 1)
    */
-  def apply[T](fn: => T, N: Int = 3, waitBeforeRetry: Option[Duration] = Some(1 millisecond)): T = {
+  def apply[T](fn: => T, N: Int = 3, waitBeforeRetry: Option[Duration] = Some(50.milliseconds)): T = {
     require(N >= 1, "maximum number of fn applications must be greater than 1")
-    waitBeforeRetry map { t =>
-      Thread.sleep(t.toMillis)
-    } // initial wait if any
-    Try { fn } match {
-      case Success(r) => r
+    waitBeforeRetry.foreach(t => Thread.sleep(t.toMillis)) // initial wait if any
+
+    try fn
+    catch {
       case _ if N > 1 =>
-        waitBeforeRetry map { t =>
-          Thread.sleep(t.toMillis)
-        }
+        waitBeforeRetry.foreach(t => Thread.sleep(t.toMillis))
         retry(fn, N - 1, waitBeforeRetry)
-      case Failure(t) => throw t
     }
   }
 }

-- 
To stop receiving notification emails like this one, please contact
rabbah@apache.org.