autoscout24 / backup-requests   1.0.32

MIT License GitHub

Library for doing backup requests

Scala versions: 2.12 2.11

Warning

This library is not really maintained anymore for years. It was updated once, but since the sunset of bintray, it cannot be published anymore. If you use this library, please consider to remove this dependency.

Backup Requests Library

Backup requests library for Scala applications. Inspired by Google's idea to do additional duplicate requests to achieve better latency. Based on the code by the "that's classifed" Autoscout24 team.

This library enables you to do additional scala.concurrent.Future executions if a former execution

  • does not return a result within some duration or

  • if they are completed with an exception

Owner

Team owning this repository: Revolistion

Status

Build Status Coverage Status Download

Setup

Add to your build.sbt following resolver with dependency:

resolvers += Resolver.bintrayRepo("tatsu-kondor", "maven")

libraryDependencies += "com.autoscout24" %% "backup-requests" % "(see version number above)"

How To Use

How to integrate it in your play guice application module:

class AppModule extends AbstractModule {
  ...
    
  @Provides @Singleton
  def backupRequests(actorSystem: ActorSystem): BackupRequests = new BackupRequests(actorSystem)

}

In your code (example):

import play.api.libs.concurrent.Execution.Implicits._
import com.autoscout24.backupRequests.BackupRequests

def doRequest[T](): () => Future[T] = ...

def backupRequestsCallback(
    maybeMetadata: Option[YetAnotherMetadata], 
    maybeFailure: Option[Throwable]): Unit = {
    
  eventPublisher.publish(BackupRequestFired(maybeFailure.isDefined, maybeFailure)(maybeMetadata))
}

backupRequests.executeWithBackup(
    doRequest, Seq(200 milliseconds), Some(scoutRequestMeta), backupRequestsCallback
)

The above code executes the doRequest() again if the initial doRequest call is not completed successfully after 200ms. If the initial (and only the initial!) call is completed with a failure, also an additional call is done. If you want more than one backup request you simply may specify more durations.

Copyright

Copyright (C) 2016 AutoScout24 GmbH.

Distributed under the MIT License.