-
Notifications
You must be signed in to change notification settings - Fork 1
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
Migrate frontend to use Tapir endpoints #28
Conversation
class RetryingBackend[P]( | ||
delegate: SttpBackend[Future, P] | ||
)(using stability: Stability) | ||
extends DelegateSttpBackend[Future, P](delegate): | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
private given retry.Success[ | ||
(Request[?, ?], Either[Throwable, Response[?]]) | ||
]((req, res) => !RetryWhen.Default(req, res)) | ||
|
||
// The default timer is currently broken in JS | ||
// https://github.com/softwaremill/odelay/pull/19 | ||
private given odelay.Timer = odelay.js.JsTimer.newTimer | ||
|
||
override def send[T, R >: P & Effect[Future]]( | ||
request: Request[T, R] | ||
): Future[Response[T]] = | ||
retry | ||
.Backoff(stability.maxRetries, stability.delay) | ||
.apply { | ||
delegate | ||
.send(request) | ||
.transform(tryResponse => | ||
scala.util.Success((request, tryResponse.toEither)) | ||
) | ||
} | ||
.flatMap { | ||
case (_, Right(response)) => Future.successful(response) | ||
case (_, Left(exception)) => Future.failed(exception) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MIgrating api.stability
to Future
s and to be used in sttp wasn't trivial, so I reimplemented an exponential backoff retrying backend using retry.
I left the original file in case we want to migrate it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to remove it completely - though I would've imagined that sttp has a retying backend built-in given that both libraries are part of softwaremillverse :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be an interesting thing to try, actually! But as far as I know, there is no retry integration for sttp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened an issue here
Good to go from my side |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a couple of nitpicks but I will fix them myself - let's see if it works in production first 🎉
No description provided.