Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
constantine2nd committed Aug 25, 2023
2 parents 2003b80 + 3d9e7d0 commit 9456178
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
24 changes: 8 additions & 16 deletions obp-api/src/main/scala/code/api/util/FutureUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,17 @@ object FutureUtil {
}

def futureWithLimits[T](future: Future[T], serviceName: String)(implicit ec: ExecutionContext): Future[T] = {

incrementFutureCounter(serviceName)

// Promise will be fulfilled with either the callers Future
val p = Promise[T]

future.map {
result =>
if (p.trySuccess(result)) {
future
.map(
value => {
decrementFutureCounter(serviceName)
}
}.recover {
case e: Exception =>
if (p.tryFailure(e)) {
value
}).recover{
case exception: Throwable =>
decrementFutureCounter(serviceName)
}
}

p.future
throw exception
}
}

}
11 changes: 4 additions & 7 deletions obp-api/src/main/scala/code/api/v3_0_0/APIMethods300.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import code.scope.Scope
import code.search.elasticsearchWarehouse
import code.users.Users
import code.util.Helper
import code.util.Helper.booleanToBox
import code.util.Helper.{booleanToBox, booleanToFuture}
import code.views.Views
import code.views.system.ViewDefinition
import com.github.dwickern.macros.NameOf.nameOf
Expand Down Expand Up @@ -2386,13 +2386,10 @@ trait APIMethods300 {
cc => implicit val ec = EndpointContext(Some(cc))
for {
(_, callContext) <- anonymousAccess(cc)
(banks, callContext) <- if(canOpenFuture("NewStyle.function.getBanks")) {
FutureUtil.futureWithLimits(NewStyle.function.getBanks(callContext), "NewStyle.function.getBanks")
} else {
Future {
throw new RuntimeException(ServiceIsTooBusy +"Current Service(NewStyle.function.getBanks) ")
}
_ <- booleanToFuture(ServiceIsTooBusy +"Current Service(NewStyle.function.getBanks)", 503, callContext) {
canOpenFuture("NewStyle.function.getBanks")
}
(banks, callContext) <- FutureUtil.futureWithLimits(NewStyle.function.getBanks(callContext), "NewStyle.function.getBanks")
} yield
(JSONFactory300.createBanksJson(banks), HttpCode.`200`(callContext))
}
Expand Down

0 comments on commit 9456178

Please sign in to comment.