Skip to content

Commit

Permalink
Retry adapter - isRetryable exposed
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbanda committed Nov 12, 2024
1 parent de9f099 commit 8b3a581
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ val scala3 = "3.2.2"

ThisBuild / organization := "io.cequence"
ThisBuild / scalaVersion := scala212
ThisBuild / version := "1.1.1.RC.9"
ThisBuild / version := "1.1.1.RC.11"
ThisBuild / isSnapshot := false

lazy val commonSettings = Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.cequence.openaiscala.service.adapter
import akka.actor.Scheduler
import akka.stream.Materializer
import io.cequence.openaiscala.RetryHelpers.RetrySettings
import io.cequence.openaiscala.Retryable
import io.cequence.openaiscala.domain.BaseMessage
import io.cequence.openaiscala.domain.settings.CreateChatCompletionSettings
import io.cequence.openaiscala.service._
Expand Down Expand Up @@ -44,13 +45,17 @@ trait OpenAIServiceAdapters[S <: CloseableService] {

def retry(
underlying: S,
log: Option[String => Unit] = None
log: Option[String => Unit] = None,
isRetryable: Throwable => Boolean = {
case Retryable(_) => true
case _ => false
}
)(
implicit ec: ExecutionContext,
retrySettings: RetrySettings,
scheduler: Scheduler
): S =
wrapAndDelegate(new RetryServiceAdapter(underlying, log))
wrapAndDelegate(new RetryServiceAdapter(underlying, log, isRetryable))

def log(
underlying: S,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package io.cequence.openaiscala.service.adapter

import akka.actor.Scheduler
import io.cequence.openaiscala.RetryHelpers
import io.cequence.openaiscala.{RetryHelpers, Retryable}
import io.cequence.openaiscala.RetryHelpers.RetrySettings
import io.cequence.wsclient.service.CloseableService

import scala.concurrent.{ExecutionContext, Future}

private class RetryServiceAdapter[+S <: CloseableService](
underlying: S,
log: Option[String => Unit] = None
log: Option[String => Unit] = None,
isRetryable: Throwable => Boolean
)(
implicit ec: ExecutionContext,
retrySettings: RetrySettings,
Expand All @@ -24,7 +25,8 @@ private class RetryServiceAdapter[+S <: CloseableService](
): Future[T] =
fun(underlying).retryOnFailure(
Some(s"${getFunctionName().capitalize} call failed"),
log
log,
isRetryable
)

override def close(): Unit =
Expand Down

0 comments on commit 8b3a581

Please sign in to comment.