Skip to content

Commit

Permalink
An execution context can't be passed down through a method call into …
Browse files Browse the repository at this point in the history
…a cache loader
  • Loading branch information
rtyley committed Aug 8, 2023
1 parent 363d9b8 commit 565d89c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions common/app/services/fronts/FrontJsonFapi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import scala.concurrent.{ExecutionContext, Future}
import scala.util.Using

trait FrontJsonFapi extends GuLogging {
implicit val executionContext: ExecutionContext
lazy val stage: String = Configuration.facia.stage.toUpperCase
val bucketLocation: String

Expand All @@ -46,7 +47,7 @@ trait FrontJsonFapi extends GuLogging {
_.maximumSize(180).expireAfterAccess(1.hour),
)

def get(path: String, pageType: PressedPageType)(implicit ec: ExecutionContext): Future[Option[PressedPage]] =
def get(path: String, pageType: PressedPageType): Future[Option[PressedPage]] =
errorLoggingF(s"FrontJsonFapi.get $path") {
val objectId = s3ObjectIdFor(path, pageType.suffix)
pressedPageCache.get(objectId).map(Some(_)).recover {
Expand All @@ -57,10 +58,10 @@ trait FrontJsonFapi extends GuLogging {
}
}

class FrontJsonFapiLive() extends FrontJsonFapi {
class FrontJsonFapiLive(implicit val executionContext: ExecutionContext) extends FrontJsonFapi {
override val bucketLocation: String = s"$stage/frontsapi/pressed/live"
}

class FrontJsonFapiDraft() extends FrontJsonFapi {
class FrontJsonFapiDraft(implicit val executionContext: ExecutionContext) extends FrontJsonFapi {
override val bucketLocation: String = s"$stage/frontsapi/pressed/draft"
}
6 changes: 2 additions & 4 deletions common/test/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,9 @@ trait WithTestCSRF {

trait WithTestFrontJsonFapi {
// need a front api that stores S3 locally so it can run without deps in the unit tests
class TestFrontJsonFapi extends FrontJsonFapiLive {
class TestFrontJsonFapi extends FrontJsonFapiLive()(ExecutionContext.global) {

override def get(path: String, pageType: PressedPageType)(implicit
executionContext: ExecutionContext,
): Future[Option[PressedPage]] = {
override def get(path: String, pageType: PressedPageType): Future[Option[PressedPage]] = {
recorder.load(path, Map()) {
super.get(path, pageType)
}
Expand Down
3 changes: 3 additions & 0 deletions facia/app/AppLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ import services._
import services.fronts.{FrontJsonFapiDraft, FrontJsonFapiLive}
import router.Routes

import scala.concurrent.ExecutionContext

class AppLoader extends FrontendApplicationLoader {
override def buildComponents(context: Context): FrontendComponents =
new BuiltInComponentsFromContext(context) with AppComponents
}

trait FapiServices {
implicit val executionContext: ExecutionContext
def wsClient: WSClient
def actorSystem: ActorSystem
lazy val frontJsonFapiLive = wire[FrontJsonFapiLive]
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object Dependencies {
val awsEc2 = "com.amazonaws" % "aws-java-sdk-ec2" % awsVersion
val awsKinesis = "com.amazonaws" % "aws-java-sdk-kinesis" % awsVersion
val awsS3 = "com.amazonaws" % "aws-java-sdk-s3" % awsVersion
val eTagCachingS3 = "com.gu.etag-caching" %% "aws-s3-sdk-v2" % "1.0.1"
val eTagCachingS3 = "com.gu.etag-caching" %% "aws-s3-sdk-v2" % "1.0.4"
val awsSes = "com.amazonaws" % "aws-java-sdk-ses" % awsVersion
val awsSns = "com.amazonaws" % "aws-java-sdk-sns" % awsVersion
val awsSts = "com.amazonaws" % "aws-java-sdk-sts" % awsVersion
Expand Down

0 comments on commit 565d89c

Please sign in to comment.