Skip to content

first stab at using retrypolicies #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions project/build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ object Common {
def settings: Seq[Setting[_]] = Seq(
organization := "me.lessis",
version := "0.1.0",
crossScalaVersions := Seq("2.9.3", "2.10.0", "2.10.1"),
scalaVersion := "2.9.3",
crossScalaVersions := Seq("2.9.3", "2.10.2"),
scalaVersion := "2.10.2",
licenses <<= version(v =>
Seq("MIT" ->
url("https://github.com/softprops/retry/blob/%s/LICENSE" format v))),
Expand Down Expand Up @@ -50,5 +50,6 @@ object Build extends sbt.Build {

lazy val netty = module("netty").dependsOn(core)

lazy val twitter = module("twitter").dependsOn(core)
lazy val twitter = module("twitter")
.dependsOn(core)
}
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ addSbtPlugin("me.lessis" % "ls-sbt" % "0.1.2")

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.2.0")

addSbtPlugin("com.jsuereth" % "xsbt-gpg-plugin" % "0.6")
//addSbtPlugin("com.jsuereth" % "xsbt-gpg-plugin" % "0.6")
10 changes: 5 additions & 5 deletions twitter/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ organization := "me.lessis"

name := "retry-twitter"

libraryDependencies += "com.twitter" % "util-core" % "6.3.4"
libraryDependencies ++= Seq(
"com.twitter" %% "util-core" % "6.3.4",
"com.twitter" %% "util-zk" % "6.3.4",
"com.twitter" %% "bijection-util" % "0.5.2" exclude("org.scalacheck", "scalacheck_2.10") exclude("org.scala-tools.testing", "specs_2.10")
)

description := "provides a retry.Timer implementation backed by a com.twitter.util.Timer"

resolvers += "twitter" at "http://maven.twttr.com/"

crossScalaVersions := Seq("2.10.0", "2.10.1")

scalaVersion := "2.10.0"
20 changes: 20 additions & 0 deletions twitter/src/main/scala/retrypolicyconverters.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package retry

import com.twitter.util.{Future => TwitterFuture, Return, Throw}
import com.twitter.zk.{RetryPolicy => TwitterRetryPolicy}
import com.twitter.bijection.twitter_util.UtilBijections.twitter2ScalaFuture
import com.twitter.bijection.Conversion.asMethod
import scala.concurrent.{Future => ScalaFuture, ExecutionContext}
import scala.concurrent.ExecutionContext.Implicits.global

object RetryPolicyConverters {
val defaultContext = global

def retryPolicyToRetrier(policy: TwitterRetryPolicy): ScalaRetryPolicy = new ScalaRetryPolicy(policy, defaultContext)
}

class ScalaRetryPolicy(policy: TwitterRetryPolicy, context: ExecutionContext) {
implicit val ctxt = context

def apply[A](op: => ScalaFuture[A]): ScalaFuture[A] = policy(op.as[TwitterFuture[A]]).as[ScalaFuture[A]]
}