From 6b1179e137a41969b7d0bfef99eb41d049e068af Mon Sep 17 00:00:00 2001 From: DanielCliftonGuardian <110032454+DanielCliftonGuardian@users.noreply.github.com> Date: Wed, 6 Sep 2023 12:46:56 +0100 Subject: [PATCH 1/8] migrate ActorSystem to pekko --- admin/app/AppLoader.scala | 2 +- admin/test/dfp/DfpApiValidationTest.scala | 2 +- admin/test/services/ParameterStoreServiceTest.scala | 2 +- applications/app/AppLoader.scala | 2 +- archive/app/AppLoader.scala | 2 +- article/app/AppLoader.scala | 2 +- .../app/services/NewspaperBooksAndSectionsAutoRefresh.scala | 2 +- build.sbt | 1 + commercial/app/AppLoader.scala | 2 +- commercial/app/model/merchandise/books/BookFinder.scala | 2 +- common/app/common/AutoRefresh.scala | 2 +- common/app/common/Logback/KinesisAdapter.scala | 6 +++--- common/app/concurrent/BlockingOperations.scala | 4 ++-- common/app/concurrent/CircuitBreakerRegistry.scala | 4 ++-- common/app/contentapi/ContentApiClient.scala | 2 +- common/app/renderers/DotcomRenderingService.scala | 2 +- common/app/services/indexAutoRefreshes.scala | 2 +- common/test/concurrent/BlockingOperationsTest.scala | 2 +- common/test/package.scala | 2 +- dev-build/app/AppLoader.scala | 2 +- discussion/app/AppLoader.scala | 2 +- facia-press/app/AppLoader.scala | 2 +- facia/app/AppLoader.scala | 2 +- facia/test/FaciaControllerTest.scala | 2 +- facia/test/FaciaMetaDataTest.scala | 2 +- identity/app/AppLoader.scala | 2 +- onward/app/AppLoader.scala | 2 +- onward/app/business/StocksDataLifecycle.scala | 2 +- onward/app/controllers/OnwardControllers.scala | 2 +- onward/app/feed/MostPopularSocialAutoRefresh.scala | 2 +- onward/test/weather/WeatherApiTest.scala | 2 +- preview/app/AppLoader.scala | 2 +- project/Dependencies.scala | 3 +++ rss/app/AppLoader.scala | 2 +- sport/app/AppLoader.scala | 2 +- sport/app/cricket/feed/cricketPaFeed.scala | 2 +- 36 files changed, 42 insertions(+), 38 deletions(-) diff --git a/admin/app/AppLoader.scala b/admin/app/AppLoader.scala index ffd0191520a8..d42ae8bb4c0b 100644 --- a/admin/app/AppLoader.scala +++ b/admin/app/AppLoader.scala @@ -8,7 +8,7 @@ import conf.switches.SwitchboardLifecycle import conf.CachedHealthCheckLifeCycle import controllers.{AdminControllers, HealthCheck} import _root_.dfp.DfpDataCacheLifecycle -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import concurrent.BlockingOperations import contentapi.{CapiHttpClient, ContentApiClient, HttpClient} import http.{AdminFilters, AdminHttpErrorHandler, CommonGzipFilter} diff --git a/admin/test/dfp/DfpApiValidationTest.scala b/admin/test/dfp/DfpApiValidationTest.scala index 2e71212d19e0..a739aba52b5d 100644 --- a/admin/test/dfp/DfpApiValidationTest.scala +++ b/admin/test/dfp/DfpApiValidationTest.scala @@ -4,7 +4,7 @@ import concurrent.BlockingOperations import common.dfp.{GuAdUnit, GuLineItem, GuTargeting, Sponsorship} import com.google.api.ads.admanager.axis.v202308._ import org.joda.time.DateTime -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers diff --git a/admin/test/services/ParameterStoreServiceTest.scala b/admin/test/services/ParameterStoreServiceTest.scala index 6cedfb4c1965..3488911ba0f3 100644 --- a/admin/test/services/ParameterStoreServiceTest.scala +++ b/admin/test/services/ParameterStoreServiceTest.scala @@ -1,6 +1,6 @@ package services -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import concurrent.BlockingOperations import org.scalatest.concurrent.ScalaFutures import org.mockito.Mockito._ diff --git a/applications/app/AppLoader.scala b/applications/app/AppLoader.scala index 019c5a59215d..79cc9355588c 100644 --- a/applications/app/AppLoader.scala +++ b/applications/app/AppLoader.scala @@ -1,4 +1,4 @@ -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents} import com.softwaremill.macwire._ import common.dfp.DfpAgentLifecycle diff --git a/archive/app/AppLoader.scala b/archive/app/AppLoader.scala index f25ea78aa1b3..247cd4b842aa 100644 --- a/archive/app/AppLoader.scala +++ b/archive/app/AppLoader.scala @@ -1,4 +1,4 @@ -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import http.{CommonFilters, CorsHttpErrorHandler} import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents} import com.softwaremill.macwire._ diff --git a/article/app/AppLoader.scala b/article/app/AppLoader.scala index cec8344dda6a..ab2bfe35bd04 100644 --- a/article/app/AppLoader.scala +++ b/article/app/AppLoader.scala @@ -1,5 +1,5 @@ import _root_.commercial.targeting.TargetingLifecycle -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents} import com.softwaremill.macwire._ import common.Assets.DiscussionExternalAssetsLifecycle diff --git a/article/app/services/NewspaperBooksAndSectionsAutoRefresh.scala b/article/app/services/NewspaperBooksAndSectionsAutoRefresh.scala index c5819864fe8e..a50b1995f5dd 100644 --- a/article/app/services/NewspaperBooksAndSectionsAutoRefresh.scala +++ b/article/app/services/NewspaperBooksAndSectionsAutoRefresh.scala @@ -1,6 +1,6 @@ package services -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import app.LifecycleComponent import common.AutoRefresh import model.{TagDefinition, TagIndexListings} diff --git a/build.sbt b/build.sbt index 8aadf0aa4552..576bb45defde 100644 --- a/build.sbt +++ b/build.sbt @@ -70,6 +70,7 @@ val common = library("common") identityModel, capiAws, okhttp, + pekkoActor, ) ++ jackson, TestAssets / mappings ~= filterAssets, ) diff --git a/commercial/app/AppLoader.scala b/commercial/app/AppLoader.scala index fd1da57a6ba0..34b7030d250a 100644 --- a/commercial/app/AppLoader.scala +++ b/commercial/app/AppLoader.scala @@ -1,4 +1,4 @@ -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents} import com.softwaremill.macwire._ import commercial.CommercialLifecycle diff --git a/commercial/app/model/merchandise/books/BookFinder.scala b/commercial/app/model/merchandise/books/BookFinder.scala index 190a158052af..5ed270fe9e96 100644 --- a/commercial/app/model/merchandise/books/BookFinder.scala +++ b/commercial/app/model/merchandise/books/BookFinder.scala @@ -1,6 +1,6 @@ package commercial.model.merchandise.books -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import akka.pattern.CircuitBreaker import akka.util.Timeout import commercial.model.feeds.{FeedParseException, FeedReadException, FeedReader, FeedRequest} diff --git a/common/app/common/AutoRefresh.scala b/common/app/common/AutoRefresh.scala index 5e95f62d5e7a..ad2f934d97ac 100644 --- a/common/app/common/AutoRefresh.scala +++ b/common/app/common/AutoRefresh.scala @@ -1,7 +1,7 @@ package common import scala.concurrent.duration.FiniteDuration -import akka.actor.{ActorSystem, Cancellable} +import org.apache.pekko.actor.{ActorSystem, Cancellable} import scala.concurrent.{ExecutionContext, Future} import scala.util.{Failure, Success} diff --git a/common/app/common/Logback/KinesisAdapter.scala b/common/app/common/Logback/KinesisAdapter.scala index e0cd84ee8387..afa0f4e1b913 100644 --- a/common/app/common/Logback/KinesisAdapter.scala +++ b/common/app/common/Logback/KinesisAdapter.scala @@ -1,9 +1,9 @@ package common.Logback import java.util.concurrent.ThreadPoolExecutor -import akka.actor.ActorSystem -import akka.dispatch.MessageDispatcher -import akka.pattern.CircuitBreaker +import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.dispatch.MessageDispatcher +import org.apache.pekko.pattern.CircuitBreaker import ch.qos.logback.classic.spi.ILoggingEvent import com.amazonaws.ClientConfiguration import com.amazonaws.auth.AWSCredentialsProvider diff --git a/common/app/concurrent/BlockingOperations.scala b/common/app/concurrent/BlockingOperations.scala index 5b59bcefea67..bb4865ed7a94 100644 --- a/common/app/concurrent/BlockingOperations.scala +++ b/common/app/concurrent/BlockingOperations.scala @@ -1,7 +1,7 @@ package concurrent -import akka.actor.ActorSystem -import akka.dispatch.MessageDispatcher +import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.dispatch.MessageDispatcher import scala.concurrent.Future diff --git a/common/app/concurrent/CircuitBreakerRegistry.scala b/common/app/concurrent/CircuitBreakerRegistry.scala index 85d70ef71f49..e88a2d98042c 100644 --- a/common/app/concurrent/CircuitBreakerRegistry.scala +++ b/common/app/concurrent/CircuitBreakerRegistry.scala @@ -1,7 +1,7 @@ package concurrent -import akka.actor.ActorSystem -import akka.pattern.CircuitBreaker +import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.pattern.CircuitBreaker import common.GuLogging import scala.concurrent.ExecutionContext.Implicits.global diff --git a/common/app/contentapi/ContentApiClient.scala b/common/app/contentapi/ContentApiClient.scala index efdb72b8cb3d..9b4ab17fb4da 100644 --- a/common/app/contentapi/ContentApiClient.scala +++ b/common/app/contentapi/ContentApiClient.scala @@ -2,7 +2,7 @@ package contentapi import java.util.concurrent.TimeUnit -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import com.github.nscala_time.time.Implicits._ import com.gu.contentapi.client.model._ import com.gu.contentapi.client.model.v1.{Edition => _, _} diff --git a/common/app/renderers/DotcomRenderingService.scala b/common/app/renderers/DotcomRenderingService.scala index e291d6899908..b3be8be5d322 100644 --- a/common/app/renderers/DotcomRenderingService.scala +++ b/common/app/renderers/DotcomRenderingService.scala @@ -1,6 +1,6 @@ package renderers -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import com.gu.contentapi.client.model.v1.{Block, Blocks, Content} import common.{DCRMetrics, GuLogging} import concurrent.CircuitBreakerRegistry diff --git a/common/app/services/indexAutoRefreshes.scala b/common/app/services/indexAutoRefreshes.scala index 15b4f5253400..b4160d1c3241 100644 --- a/common/app/services/indexAutoRefreshes.scala +++ b/common/app/services/indexAutoRefreshes.scala @@ -1,6 +1,6 @@ package services -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import app.LifecycleComponent import common.AutoRefresh import model.TagIndexListings diff --git a/common/test/concurrent/BlockingOperationsTest.scala b/common/test/concurrent/BlockingOperationsTest.scala index c8f45cb6eb36..7928ace705a6 100644 --- a/common/test/concurrent/BlockingOperationsTest.scala +++ b/common/test/concurrent/BlockingOperationsTest.scala @@ -1,6 +1,6 @@ package concurrent -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import org.scalatest.concurrent.ScalaFutures import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers diff --git a/common/test/package.scala b/common/test/package.scala index 7f611c4985d5..5fbf82931da2 100644 --- a/common/test/package.scala +++ b/common/test/package.scala @@ -1,6 +1,6 @@ package test -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import java.io.File import java.net.URL diff --git a/dev-build/app/AppLoader.scala b/dev-build/app/AppLoader.scala index dc1c3ffae199..d70f447cfd9b 100644 --- a/dev-build/app/AppLoader.scala +++ b/dev-build/app/AppLoader.scala @@ -1,7 +1,7 @@ import _root_.commercial.CommercialLifecycle import _root_.commercial.controllers.CommercialControllers import _root_.commercial.targeting.TargetingLifecycle -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import agents.MostViewedAgent import app.{FrontendApplicationLoader, FrontendComponents, LifecycleComponent} import business.StocksDataLifecycle diff --git a/discussion/app/AppLoader.scala b/discussion/app/AppLoader.scala index 685f15dd41d8..b6f8c5445d76 100644 --- a/discussion/app/AppLoader.scala +++ b/discussion/app/AppLoader.scala @@ -1,4 +1,4 @@ -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import dev.DevAssetsController import http.{CommonFilters, CorsHttpErrorHandler} import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents} diff --git a/facia-press/app/AppLoader.scala b/facia-press/app/AppLoader.scala index 8c25f4a19eb4..6757c31e326d 100644 --- a/facia-press/app/AppLoader.scala +++ b/facia-press/app/AppLoader.scala @@ -15,7 +15,7 @@ import play.api.mvc.EssentialFilter import services.ConfigAgentLifecycle import router.Routes import _root_.commercial.targeting.TargetingLifecycle -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem class AppLoader extends FrontendApplicationLoader { override def buildComponents(context: Context): FrontendComponents = diff --git a/facia/app/AppLoader.scala b/facia/app/AppLoader.scala index 61bb52bf55d0..79d79e4fcf2f 100644 --- a/facia/app/AppLoader.scala +++ b/facia/app/AppLoader.scala @@ -1,5 +1,5 @@ import agents.{DeeplyReadAgent, MostViewedAgent} -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents} import com.softwaremill.macwire._ import common._ diff --git a/facia/test/FaciaControllerTest.scala b/facia/test/FaciaControllerTest.scala index 8fd94abeb864..3b8fd8118f7b 100644 --- a/facia/test/FaciaControllerTest.scala +++ b/facia/test/FaciaControllerTest.scala @@ -1,7 +1,7 @@ package test import agents.{DeeplyReadAgent, MostViewedAgent} -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import com.fasterxml.jackson.core.JsonParseException import com.gu.facia.client.models.{ConfigJson, FrontJson} import common.editions.{Uk, Us} diff --git a/facia/test/FaciaMetaDataTest.scala b/facia/test/FaciaMetaDataTest.scala index 61a5ebd04820..37dc68c8070d 100644 --- a/facia/test/FaciaMetaDataTest.scala +++ b/facia/test/FaciaMetaDataTest.scala @@ -1,7 +1,7 @@ package metadata import agents.{DeeplyReadAgent, MostViewedAgent} -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import com.gu.facia.client.models.{ConfigJson, FrontJson} import concurrent.BlockingOperations import conf.Configuration diff --git a/identity/app/AppLoader.scala b/identity/app/AppLoader.scala index 5fd65544073a..bbbd3bcc7e31 100644 --- a/identity/app/AppLoader.scala +++ b/identity/app/AppLoader.scala @@ -1,4 +1,4 @@ -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import http.IdentityHttpErrorHandler import app.{FrontendApplicationLoader, FrontendComponents} import com.softwaremill.macwire._ diff --git a/onward/app/AppLoader.scala b/onward/app/AppLoader.scala index 310bf55555b0..940d6e29d390 100644 --- a/onward/app/AppLoader.scala +++ b/onward/app/AppLoader.scala @@ -1,4 +1,4 @@ -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import http.{CommonFilters, CorsHttpErrorHandler} import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents} import business.{StocksData, StocksDataLifecycle} diff --git a/onward/app/business/StocksDataLifecycle.scala b/onward/app/business/StocksDataLifecycle.scala index fb5b01fc1f51..62868fddc132 100644 --- a/onward/app/business/StocksDataLifecycle.scala +++ b/onward/app/business/StocksDataLifecycle.scala @@ -1,6 +1,6 @@ package business -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import app.LifecycleComponent import play.api.inject.ApplicationLifecycle diff --git a/onward/app/controllers/OnwardControllers.scala b/onward/app/controllers/OnwardControllers.scala index 949f6854ecb6..637a4db1db78 100644 --- a/onward/app/controllers/OnwardControllers.scala +++ b/onward/app/controllers/OnwardControllers.scala @@ -1,6 +1,6 @@ package controllers -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import com.softwaremill.macwire._ import weather.controllers.{LocationsController, WeatherController} import business.StocksData diff --git a/onward/app/feed/MostPopularSocialAutoRefresh.scala b/onward/app/feed/MostPopularSocialAutoRefresh.scala index b7a6f7f0f52a..67b521cf00f0 100644 --- a/onward/app/feed/MostPopularSocialAutoRefresh.scala +++ b/onward/app/feed/MostPopularSocialAutoRefresh.scala @@ -1,6 +1,6 @@ package feed -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import app.LifecycleComponent import common.AutoRefresh import play.api.inject.ApplicationLifecycle diff --git a/onward/test/weather/WeatherApiTest.scala b/onward/test/weather/WeatherApiTest.scala index e02d0b7e58bb..db76fc88dbc9 100644 --- a/onward/test/weather/WeatherApiTest.scala +++ b/onward/test/weather/WeatherApiTest.scala @@ -1,6 +1,6 @@ package weather -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import org.scalatest.concurrent.ScalaFutures import play.api.libs.json.{JsString, JsValue} import org.mockito.Mockito._ diff --git a/preview/app/AppLoader.scala b/preview/app/AppLoader.scala index c3002f183dc2..525aab245a17 100644 --- a/preview/app/AppLoader.scala +++ b/preview/app/AppLoader.scala @@ -1,5 +1,5 @@ import agents.MostViewedAgent -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import app.{FrontendApplicationLoader, FrontendComponents, LifecycleComponent} import com.softwaremill.macwire._ import commercial.CommercialLifecycle diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 409996d9c80c..034a276be43d 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -6,6 +6,9 @@ object Dependencies { // Once we're able to upgrade identityLibVersion to >=4.10 we should // remove the http4s-core dependency eviction below. (Unless we've // started needing it for something else in the meantime.) + val pekkoVersion = "1.0.1" + val pekkoActor = "org.apache.pekko" %% "pekko-actor" % pekkoVersion + val pekkoStream = "org.apache.pekko" %% "pekko-stream" % pekkoVersion val identityLibVersion = "3.255" val awsVersion = "1.12.205" val capiVersion = "19.4.0" diff --git a/rss/app/AppLoader.scala b/rss/app/AppLoader.scala index 24ea9bb8407c..135a7d7374c2 100644 --- a/rss/app/AppLoader.scala +++ b/rss/app/AppLoader.scala @@ -1,4 +1,4 @@ -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents, LifecycleComponent} import com.softwaremill.macwire._ import common._ diff --git a/sport/app/AppLoader.scala b/sport/app/AppLoader.scala index afef6227c120..920c7e652eb5 100644 --- a/sport/app/AppLoader.scala +++ b/sport/app/AppLoader.scala @@ -1,4 +1,4 @@ -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import akka.stream.Materializer import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents} import com.softwaremill.macwire._ diff --git a/sport/app/cricket/feed/cricketPaFeed.scala b/sport/app/cricket/feed/cricketPaFeed.scala index cfc6f8750816..cb0f15ff505d 100644 --- a/sport/app/cricket/feed/cricketPaFeed.scala +++ b/sport/app/cricket/feed/cricketPaFeed.scala @@ -1,6 +1,6 @@ package conf.cricketPa -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import akka.stream.Materializer import common.Chronos import common.GuLogging From cfaa9a1ba0924329765249b5572cd551694fc8e0 Mon Sep 17 00:00:00 2001 From: DanielCliftonGuardian <110032454+DanielCliftonGuardian@users.noreply.github.com> Date: Thu, 7 Sep 2023 12:37:16 +0100 Subject: [PATCH 2/8] Health mob Create PekkoActorSystem Co-Authored-By: Jamie B <53781962+JamieB-gu@users.noreply.github.com> Co-Authored-By: Charlotte Emms <43961396+cemms1@users.noreply.github.com> Co-Authored-By: Ioanna Kokkini Co-Authored-By: Ashleigh Carr Co-Authored-By: Parisa Tork <47482049+ParisaTork@users.noreply.github.com> --- common/app/app/FrontendApplicationLoader.scala | 11 +++++++++-- common/app/common/akka.scala | 2 +- facia/app/AppLoader.scala | 6 +++--- onward/app/weather/WeatherApi.scala | 2 +- rss/app/AppLoader.scala | 4 ++-- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/common/app/app/FrontendApplicationLoader.scala b/common/app/app/FrontendApplicationLoader.scala index 9d2dcd99c376..7d743e4e5251 100644 --- a/common/app/app/FrontendApplicationLoader.scala +++ b/common/app/app/FrontendApplicationLoader.scala @@ -10,6 +10,7 @@ import play.api.routing.Router import play.filters.csrf.CSRFComponents import controllers.AssetsComponents import play.api.{Application, ApplicationLoader, BuiltInComponents, LoggerConfigurator, OptionalDevContext} +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} trait FrontendApplicationLoader extends ApplicationLoader { @@ -36,10 +37,16 @@ trait FrontendComponents lazy val prefix = "/" - implicit lazy val as = actorSystem + +// implicit lazy val as = actorSystem + + implicit val pekkoActorSystem: PekkoActorSystem = PekkoActorSystem.create() + applicationLifecycle.addStopHook(() => { + pekkoActorSystem.terminate() + }) lazy val jobScheduler = new JobScheduler(appContext) - lazy val akkaAsync = new AkkaAsync(environment, actorSystem) + lazy val akkaAsync = new AkkaAsync(environment, pekkoActorSystem) lazy val appMetrics = ApplicationMetrics() lazy val guardianConf = new GuardianConfiguration lazy val mode = environment.mode diff --git a/common/app/common/akka.scala b/common/app/common/akka.scala index b5eac9e89fa6..5908d9ea277d 100644 --- a/common/app/common/akka.scala +++ b/common/app/common/akka.scala @@ -4,7 +4,7 @@ import scala.concurrent.duration._ import play.api.{Environment => PlayEnv, Mode} import scala.concurrent.ExecutionContext -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem class AkkaAsync(env: PlayEnv, actorSystem: ActorSystem) { implicit val ec: ExecutionContext = actorSystem.dispatcher diff --git a/facia/app/AppLoader.scala b/facia/app/AppLoader.scala index 79d79e4fcf2f..489f57ae1f98 100644 --- a/facia/app/AppLoader.scala +++ b/facia/app/AppLoader.scala @@ -1,5 +1,5 @@ import agents.{DeeplyReadAgent, MostViewedAgent} -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents} import com.softwaremill.macwire._ import common._ @@ -35,7 +35,7 @@ class AppLoader extends FrontendApplicationLoader { trait FapiServices { implicit val executionContext: ExecutionContext def wsClient: WSClient - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem lazy val frontJsonFapiLive = wire[FrontJsonFapiLive] lazy val frontJsonFapiDraft = wire[FrontJsonFapiDraft] lazy val blockingOperations = wire[BlockingOperations] @@ -81,5 +81,5 @@ trait AppComponents extends FrontendComponents with FaciaControllers with FapiSe override lazy val httpFilters: Seq[EssentialFilter] = wire[CommonFilters].filters override lazy val httpRequestHandler: HttpRequestHandler = wire[DevParametersHttpRequestHandler] - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem } diff --git a/onward/app/weather/WeatherApi.scala b/onward/app/weather/WeatherApi.scala index 07d7c9d30cd6..4941a3fcdb69 100644 --- a/onward/app/weather/WeatherApi.scala +++ b/onward/app/weather/WeatherApi.scala @@ -3,7 +3,7 @@ package weather import java.net.{URI, URLEncoder} import java.util.concurrent.TimeoutException -import akka.actor.{ActorSystem, Scheduler} +import org.apache.pekko.actor.{ActorSystem, Scheduler} import common.{GuLogging, ResourcesHelper} import conf.Configuration import play.api.libs.json.{JsValue, Json} diff --git a/rss/app/AppLoader.scala b/rss/app/AppLoader.scala index 135a7d7374c2..25a15488b508 100644 --- a/rss/app/AppLoader.scala +++ b/rss/app/AppLoader.scala @@ -1,4 +1,4 @@ -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents, LifecycleComponent} import com.softwaremill.macwire._ import common._ @@ -61,5 +61,5 @@ trait AppComponents extends FrontendComponents { val frontendBuildInfo: FrontendBuildInfo = frontend.rss.BuildInfo override lazy val httpFilters: Seq[EssentialFilter] = wire[CommonFilters].filters override lazy val httpRequestHandler: HttpRequestHandler = wire[DevParametersHttpRequestHandler] - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem } From 257c0ec3688c790d95dea496d9bf57479d8e524a Mon Sep 17 00:00:00 2001 From: DanielCliftonGuardian <110032454+DanielCliftonGuardian@users.noreply.github.com> Date: Fri, 8 Sep 2023 12:21:47 +0100 Subject: [PATCH 3/8] compiling --- admin/app/AppLoader.scala | 6 +++--- applications/app/AppLoader.scala | 4 ++-- archive/app/AppLoader.scala | 5 ++--- article/app/AppLoader.scala | 4 ++-- build.sbt | 1 + commercial/app/AppLoader.scala | 6 +++--- .../model/merchandise/books/BookFinder.scala | 14 ++++++------- discussion/app/AppLoader.scala | 4 ++-- facia-press/app/AppLoader.scala | 4 ++-- identity/app/AppLoader.scala | 4 ++-- onward/app/AppLoader.scala | 6 +++--- .../app/controllers/OnwardControllers.scala | 4 ++-- onward/app/weather/WeatherApi.scala | 4 ++-- preview/app/AppLoader.scala | 4 ++-- sport/app/AppLoader.scala | 13 +++++++----- sport/app/cricket/feed/CricketThrottler.scala | 20 ++++++++++--------- sport/app/cricket/feed/cricketPaFeed.scala | 3 ++- 17 files changed, 56 insertions(+), 50 deletions(-) diff --git a/admin/app/AppLoader.scala b/admin/app/AppLoader.scala index d42ae8bb4c0b..c47ff78e856c 100644 --- a/admin/app/AppLoader.scala +++ b/admin/app/AppLoader.scala @@ -8,7 +8,7 @@ import conf.switches.SwitchboardLifecycle import conf.CachedHealthCheckLifeCycle import controllers.{AdminControllers, HealthCheck} import _root_.dfp.DfpDataCacheLifecycle -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import concurrent.BlockingOperations import contentapi.{CapiHttpClient, ContentApiClient, HttpClient} import http.{AdminFilters, AdminHttpErrorHandler, CommonGzipFilter} @@ -36,7 +36,7 @@ class AppLoader extends FrontendApplicationLoader { trait AdminServices extends I18nComponents { def wsClient: WSClient def akkaAsync: AkkaAsync - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem implicit val executionContext: ExecutionContext lazy val capiHttpClient: HttpClient = wire[CapiHttpClient] lazy val contentApiClient = wire[ContentApiClient] @@ -101,7 +101,7 @@ trait AppComponents extends FrontendComponents with AdminControllers with AdminS DfpApiMetrics.DfpApiErrors, ) - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem override lazy val httpErrorHandler: HttpErrorHandler = wire[AdminHttpErrorHandler] override lazy val httpFilters: Seq[EssentialFilter] = wire[CommonGzipFilter].filters ++ wire[AdminFilters].filters diff --git a/applications/app/AppLoader.scala b/applications/app/AppLoader.scala index 79cc9355588c..d83fe2d301b7 100644 --- a/applications/app/AppLoader.scala +++ b/applications/app/AppLoader.scala @@ -1,4 +1,4 @@ -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents} import com.softwaremill.macwire._ import common.dfp.DfpAgentLifecycle @@ -97,5 +97,5 @@ trait AppComponents extends FrontendComponents with ApplicationsControllers with override lazy val httpFilters: Seq[EssentialFilter] = wire[CommonFilters].filters override lazy val httpRequestHandler: HttpRequestHandler = wire[DevParametersHttpRequestHandler] - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem } diff --git a/archive/app/AppLoader.scala b/archive/app/AppLoader.scala index 247cd4b842aa..66f354e93b58 100644 --- a/archive/app/AppLoader.scala +++ b/archive/app/AppLoader.scala @@ -1,4 +1,4 @@ -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import http.{CommonFilters, CorsHttpErrorHandler} import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents} import com.softwaremill.macwire._ @@ -49,6 +49,5 @@ trait AppComponents extends FrontendComponents { override lazy val httpErrorHandler: HttpErrorHandler = wire[CorsHttpErrorHandler] override lazy val httpFilters: Seq[EssentialFilter] = wire[CommonFilters].filters override lazy val httpRequestHandler: HttpRequestHandler = wire[DevParametersHttpRequestHandler] - - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem } diff --git a/article/app/AppLoader.scala b/article/app/AppLoader.scala index ab2bfe35bd04..415624079cb4 100644 --- a/article/app/AppLoader.scala +++ b/article/app/AppLoader.scala @@ -1,5 +1,5 @@ import _root_.commercial.targeting.TargetingLifecycle -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents} import com.softwaremill.macwire._ import common.Assets.DiscussionExternalAssetsLifecycle @@ -98,5 +98,5 @@ trait AppComponents extends FrontendComponents with ArticleControllers with Topi override lazy val httpFilters: Seq[EssentialFilter] = wire[CommonFilters].filters override lazy val httpRequestHandler: HttpRequestHandler = wire[DevParametersHttpRequestHandler] - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem } diff --git a/build.sbt b/build.sbt index 576bb45defde..0d7558c6b4ff 100644 --- a/build.sbt +++ b/build.sbt @@ -71,6 +71,7 @@ val common = library("common") capiAws, okhttp, pekkoActor, + pekkoStream, ) ++ jackson, TestAssets / mappings ~= filterAssets, ) diff --git a/commercial/app/AppLoader.scala b/commercial/app/AppLoader.scala index 34b7030d250a..171332b9ee31 100644 --- a/commercial/app/AppLoader.scala +++ b/commercial/app/AppLoader.scala @@ -1,4 +1,4 @@ -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents} import com.softwaremill.macwire._ import commercial.CommercialLifecycle @@ -35,7 +35,7 @@ class AppLoader extends FrontendApplicationLoader { trait CommercialServices { def wsClient: WSClient - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem implicit val executionContext: ExecutionContext lazy val magentoService = wire[MagentoService] @@ -79,5 +79,5 @@ trait AppComponents extends FrontendComponents with CommercialControllers with C override lazy val httpFilters: Seq[EssentialFilter] = wire[CommonFilters].filters override lazy val httpRequestHandler: HttpRequestHandler = wire[DevParametersHttpRequestHandler] - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem } diff --git a/commercial/app/model/merchandise/books/BookFinder.scala b/commercial/app/model/merchandise/books/BookFinder.scala index 5ed270fe9e96..4c6560c509b9 100644 --- a/commercial/app/model/merchandise/books/BookFinder.scala +++ b/commercial/app/model/merchandise/books/BookFinder.scala @@ -1,12 +1,12 @@ package commercial.model.merchandise.books -import org.apache.pekko.actor.ActorSystem -import akka.pattern.CircuitBreaker +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import akka.util.Timeout import commercial.model.feeds.{FeedParseException, FeedReadException, FeedReader, FeedRequest} import commercial.model.merchandise.Book import common.{Box, GuLogging} import conf.Configuration +import org.apache.pekko.pattern.CircuitBreaker import play.api.libs.json._ import play.api.libs.oauth.{ConsumerKey, OAuthCalculator, RequestToken} import play.api.libs.ws.{WSClient, WSSignatureCalculator} @@ -15,10 +15,10 @@ import scala.concurrent.duration._ import scala.concurrent.{ExecutionContext, Future} import scala.util.{Failure, Success} -class BookFinder(actorSystem: ActorSystem, magentoService: MagentoService) extends GuLogging { +class BookFinder(pekkoActorSystem: PekkoActorSystem, magentoService: MagentoService) extends GuLogging { private implicit val bookActorExecutionContext: ExecutionContext = - actorSystem.dispatchers.lookup("akka.actor.book-lookup") + pekkoActorSystem.dispatchers.lookup("akka.actor.book-lookup") private implicit val bookActorTimeout: Timeout = 0.2.seconds private implicit val magentoServiceImplicit = magentoService @@ -48,7 +48,7 @@ object BookAgent extends GuLogging { } } -class MagentoService(actorSystem: ActorSystem, wsClient: WSClient) extends GuLogging { +class MagentoService(pekkoActorSystem: PekkoActorSystem, wsClient: WSClient) extends GuLogging { private case class MagentoProperties(oauth: WSSignatureCalculator, urlPrefix: String) @@ -72,10 +72,10 @@ class MagentoService(actorSystem: ActorSystem, wsClient: WSClient) extends GuLog } private implicit val bookLookupExecutionContext: ExecutionContext = - actorSystem.dispatchers.lookup("akka.actor.book-lookup") + pekkoActorSystem.dispatchers.lookup("akka.actor.book-lookup") private final val circuitBreaker = new CircuitBreaker( - scheduler = actorSystem.scheduler, + scheduler = pekkoActorSystem.scheduler, maxFailures = 5, callTimeout = 3.seconds, resetTimeout = 5.minutes, diff --git a/discussion/app/AppLoader.scala b/discussion/app/AppLoader.scala index b6f8c5445d76..a2e41ff4c711 100644 --- a/discussion/app/AppLoader.scala +++ b/discussion/app/AppLoader.scala @@ -1,4 +1,4 @@ -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import dev.DevAssetsController import http.{CommonFilters, CorsHttpErrorHandler} import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents} @@ -49,5 +49,5 @@ trait AppComponents extends FrontendComponents with DiscussionControllers with D val frontendBuildInfo: FrontendBuildInfo = frontend.discussion.BuildInfo override lazy val httpErrorHandler: HttpErrorHandler = wire[CorsHttpErrorHandler] override lazy val httpFilters: Seq[EssentialFilter] = wire[CommonFilters].filters - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem } diff --git a/facia-press/app/AppLoader.scala b/facia-press/app/AppLoader.scala index 6757c31e326d..5dcbfb3a3fff 100644 --- a/facia-press/app/AppLoader.scala +++ b/facia-press/app/AppLoader.scala @@ -15,7 +15,7 @@ import play.api.mvc.EssentialFilter import services.ConfigAgentLifecycle import router.Routes import _root_.commercial.targeting.TargetingLifecycle -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} class AppLoader extends FrontendApplicationLoader { override def buildComponents(context: Context): FrontendComponents = @@ -64,5 +64,5 @@ trait AppComponents extends FrontendComponents { ) override lazy val httpFilters: Seq[EssentialFilter] = Nil - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem } diff --git a/identity/app/AppLoader.scala b/identity/app/AppLoader.scala index bbbd3bcc7e31..aedee0c012ce 100644 --- a/identity/app/AppLoader.scala +++ b/identity/app/AppLoader.scala @@ -1,4 +1,4 @@ -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import http.IdentityHttpErrorHandler import app.{FrontendApplicationLoader, FrontendComponents} import com.softwaremill.macwire._ @@ -45,7 +45,7 @@ trait AppLifecycleComponents { wire[NewsletterSignupLifecycle], ) - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem } trait AppComponents diff --git a/onward/app/AppLoader.scala b/onward/app/AppLoader.scala index 940d6e29d390..e90de224f027 100644 --- a/onward/app/AppLoader.scala +++ b/onward/app/AppLoader.scala @@ -1,4 +1,4 @@ -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import http.{CommonFilters, CorsHttpErrorHandler} import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents} import business.{StocksData, StocksDataLifecycle} @@ -35,7 +35,7 @@ class AppLoader extends FrontendApplicationLoader { trait OnwardServices { def wsClient: WSClient def environment: Environment - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem implicit def appContext: ApplicationContext implicit val executionContext: ExecutionContext lazy val capiHttpClient: HttpClient = wire[CapiHttpClient] @@ -88,5 +88,5 @@ trait AppComponents extends FrontendComponents with OnwardControllers with Onwar override lazy val httpRequestHandler: HttpRequestHandler = wire[DevParametersHttpRequestHandler] override lazy val httpErrorHandler: HttpErrorHandler = wire[CorsHttpErrorHandler] - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem } diff --git a/onward/app/controllers/OnwardControllers.scala b/onward/app/controllers/OnwardControllers.scala index 637a4db1db78..4919dc626398 100644 --- a/onward/app/controllers/OnwardControllers.scala +++ b/onward/app/controllers/OnwardControllers.scala @@ -1,6 +1,6 @@ package controllers -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import com.softwaremill.macwire._ import weather.controllers.{LocationsController, WeatherController} import business.StocksData @@ -30,7 +30,7 @@ trait OnwardControllers { def mostViewedVideoAgent: MostViewedVideoAgent def mostViewedGalleryAgent: MostViewedGalleryAgent def mostViewedAudioAgent: MostViewedAudioAgent - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem def controllerComponents: ControllerComponents def remoteRenderer: DotcomRenderingService def popularInTagService: PopularInTagService diff --git a/onward/app/weather/WeatherApi.scala b/onward/app/weather/WeatherApi.scala index 4941a3fcdb69..8dd242b61d84 100644 --- a/onward/app/weather/WeatherApi.scala +++ b/onward/app/weather/WeatherApi.scala @@ -2,7 +2,6 @@ package weather import java.net.{URI, URLEncoder} import java.util.concurrent.TimeoutException - import org.apache.pekko.actor.{ActorSystem, Scheduler} import common.{GuLogging, ResourcesHelper} import conf.Configuration @@ -16,10 +15,11 @@ import model.ApplicationContext import scala.concurrent.duration._ import play.api.{MarkerContext, Mode} import net.logstash.logback.marker.Markers.append +import org.apache.pekko.pattern.after import scala.concurrent.{ExecutionContext, Future} import scala.util.control.NonFatal -import akka.pattern.after + class WeatherApi(wsClient: WSClient, context: ApplicationContext, actorSystem: ActorSystem)(implicit ec: ExecutionContext, diff --git a/preview/app/AppLoader.scala b/preview/app/AppLoader.scala index 525aab245a17..9819fd3b1a45 100644 --- a/preview/app/AppLoader.scala +++ b/preview/app/AppLoader.scala @@ -1,5 +1,5 @@ import agents.MostViewedAgent -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import app.{FrontendApplicationLoader, FrontendComponents, LifecycleComponent} import com.softwaremill.macwire._ import commercial.CommercialLifecycle @@ -68,7 +68,7 @@ trait PreviewLifecycleComponents wire[MessageUsLifecycle], ) - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem } trait PreviewControllerComponents diff --git a/sport/app/AppLoader.scala b/sport/app/AppLoader.scala index 920c7e652eb5..c19dcdf8ff16 100644 --- a/sport/app/AppLoader.scala +++ b/sport/app/AppLoader.scala @@ -1,5 +1,5 @@ -import org.apache.pekko.actor.ActorSystem -import akka.stream.Materializer + +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents} import com.softwaremill.macwire._ import common.Logback.{LogbackOperationsPool, LogstashLifecycle} @@ -16,6 +16,7 @@ import football.controllers.{FootballControllers, HealthCheck} import http.{CommonFilters, CorsHttpErrorHandler} import jobs.CricketStatsJob import model.ApplicationIdentity +import org.apache.pekko.stream.{Materializer => PekkoMaterializer} import play.api.ApplicationLoader.Context import play.api.BuiltInComponentsFromContext import play.api.http.{HttpErrorHandler, HttpRequestHandler} @@ -39,8 +40,10 @@ class AppLoader extends FrontendApplicationLoader { trait SportServices { def wsClient: WSClient - def actorSystem: ActorSystem - def materializer: Materializer + def pekkoActorSystem: PekkoActorSystem + + def pekkoMaterializer: PekkoMaterializer = PekkoMaterializer.matFromSystem(pekkoActorSystem) + implicit val executionContext: ExecutionContext lazy val capiHttpClient: HttpClient = wire[CapiHttpClient] @@ -87,5 +90,5 @@ trait AppComponents override lazy val httpFilters: Seq[EssentialFilter] = wire[CommonFilters].filters override lazy val httpRequestHandler: HttpRequestHandler = wire[DevParametersHttpRequestHandler] override lazy val httpErrorHandler: HttpErrorHandler = wire[CorsHttpErrorHandler] - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem } diff --git a/sport/app/cricket/feed/CricketThrottler.scala b/sport/app/cricket/feed/CricketThrottler.scala index 2a68fa76e426..f548b1f5e09c 100644 --- a/sport/app/cricket/feed/CricketThrottler.scala +++ b/sport/app/cricket/feed/CricketThrottler.scala @@ -1,13 +1,15 @@ package cricket.feed + +import org.apache.pekko.NotUsed +import org.apache.pekko.pattern.{ask, pipe} +import org.apache.pekko.stream.{CompletionStrategy, Materializer, OverflowStrategy, ThrottleMode} + import java.util.concurrent.TimeUnit -import akka.NotUsed -import akka.actor.Status.{Failure, Success} -import akka.actor.{Actor, ActorRef, ActorSystem, Props} -import akka.pattern.{ask, pipe} -import akka.stream.scaladsl.{Sink, Source} -import akka.stream.{CompletionStrategy, Materializer, OverflowStrategy, ThrottleMode} -import akka.util.Timeout +import org.apache.pekko.actor.{Actor, ActorRef, Props, ActorSystem => PekkoActorSystem} +import org.apache.pekko.actor.Status.{Failure, Success} +import org.apache.pekko.stream.scaladsl.{Sink, Source} +import org.apache.pekko.util.Timeout import scala.concurrent.{ExecutionContext, Future} import scala.concurrent.duration._ @@ -40,8 +42,8 @@ class CricketThrottlerActor()(implicit materializer: Materializer) extends Actor } } -class CricketThrottler(actorSystem: ActorSystem, materializer: Materializer) { - private val cricketThrottlerActor: ActorRef = actorSystem.actorOf(Props(new CricketThrottlerActor()(materializer))) +class CricketThrottler(pekkoActorSystem: PekkoActorSystem, materializer: Materializer) { + private val cricketThrottlerActor: ActorRef = pekkoActorSystem.actorOf(Props(new CricketThrottlerActor()(materializer))) def throttle[T](task: () => Future[T])(implicit ec: ExecutionContext, tag: ClassTag[T]): Future[T] = { // we have a long timeout to allow for the large number of requests to be made when the app starts up, at 1s/request diff --git a/sport/app/cricket/feed/cricketPaFeed.scala b/sport/app/cricket/feed/cricketPaFeed.scala index cb0f15ff505d..081d74a4ae6e 100644 --- a/sport/app/cricket/feed/cricketPaFeed.scala +++ b/sport/app/cricket/feed/cricketPaFeed.scala @@ -1,10 +1,11 @@ package conf.cricketPa + import org.apache.pekko.actor.ActorSystem -import akka.stream.Materializer import common.Chronos import common.GuLogging import cricket.feed.CricketThrottler +import org.apache.pekko.stream.Materializer import java.time.{LocalDate, ZoneId} import play.api.libs.ws.WSClient From 9db2e562b0190fade9638871b0c45ac3ceb17b3c Mon Sep 17 00:00:00 2001 From: DanielCliftonGuardian <110032454+DanielCliftonGuardian@users.noreply.github.com> Date: Fri, 8 Sep 2023 12:22:49 +0100 Subject: [PATCH 4/8] scalafmt --- common/app/app/FrontendApplicationLoader.scala | 1 - onward/app/weather/WeatherApi.scala | 1 - sport/app/AppLoader.scala | 1 - sport/app/cricket/feed/CricketThrottler.scala | 4 ++-- sport/app/cricket/feed/cricketPaFeed.scala | 1 - 5 files changed, 2 insertions(+), 6 deletions(-) diff --git a/common/app/app/FrontendApplicationLoader.scala b/common/app/app/FrontendApplicationLoader.scala index 7d743e4e5251..f61406e670d5 100644 --- a/common/app/app/FrontendApplicationLoader.scala +++ b/common/app/app/FrontendApplicationLoader.scala @@ -37,7 +37,6 @@ trait FrontendComponents lazy val prefix = "/" - // implicit lazy val as = actorSystem implicit val pekkoActorSystem: PekkoActorSystem = PekkoActorSystem.create() diff --git a/onward/app/weather/WeatherApi.scala b/onward/app/weather/WeatherApi.scala index 8dd242b61d84..7b8c6f79ec1c 100644 --- a/onward/app/weather/WeatherApi.scala +++ b/onward/app/weather/WeatherApi.scala @@ -20,7 +20,6 @@ import org.apache.pekko.pattern.after import scala.concurrent.{ExecutionContext, Future} import scala.util.control.NonFatal - class WeatherApi(wsClient: WSClient, context: ApplicationContext, actorSystem: ActorSystem)(implicit ec: ExecutionContext, ) extends ResourcesHelper diff --git a/sport/app/AppLoader.scala b/sport/app/AppLoader.scala index c19dcdf8ff16..531ae38bba6b 100644 --- a/sport/app/AppLoader.scala +++ b/sport/app/AppLoader.scala @@ -1,4 +1,3 @@ - import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import app.{FrontendApplicationLoader, FrontendBuildInfo, FrontendComponents} import com.softwaremill.macwire._ diff --git a/sport/app/cricket/feed/CricketThrottler.scala b/sport/app/cricket/feed/CricketThrottler.scala index f548b1f5e09c..c7036b5aeb33 100644 --- a/sport/app/cricket/feed/CricketThrottler.scala +++ b/sport/app/cricket/feed/CricketThrottler.scala @@ -1,6 +1,5 @@ package cricket.feed - import org.apache.pekko.NotUsed import org.apache.pekko.pattern.{ask, pipe} import org.apache.pekko.stream.{CompletionStrategy, Materializer, OverflowStrategy, ThrottleMode} @@ -43,7 +42,8 @@ class CricketThrottlerActor()(implicit materializer: Materializer) extends Actor } class CricketThrottler(pekkoActorSystem: PekkoActorSystem, materializer: Materializer) { - private val cricketThrottlerActor: ActorRef = pekkoActorSystem.actorOf(Props(new CricketThrottlerActor()(materializer))) + private val cricketThrottlerActor: ActorRef = + pekkoActorSystem.actorOf(Props(new CricketThrottlerActor()(materializer))) def throttle[T](task: () => Future[T])(implicit ec: ExecutionContext, tag: ClassTag[T]): Future[T] = { // we have a long timeout to allow for the large number of requests to be made when the app starts up, at 1s/request diff --git a/sport/app/cricket/feed/cricketPaFeed.scala b/sport/app/cricket/feed/cricketPaFeed.scala index 081d74a4ae6e..cc190f714835 100644 --- a/sport/app/cricket/feed/cricketPaFeed.scala +++ b/sport/app/cricket/feed/cricketPaFeed.scala @@ -1,6 +1,5 @@ package conf.cricketPa - import org.apache.pekko.actor.ActorSystem import common.Chronos import common.GuLogging From 003f097d5a89813c1ddffa3437d362ef6cc648c2 Mon Sep 17 00:00:00 2001 From: DanielCliftonGuardian <110032454+DanielCliftonGuardian@users.noreply.github.com> Date: Fri, 8 Sep 2023 13:30:01 +0100 Subject: [PATCH 5/8] migrate other usages --- commercial/app/model/merchandise/books/BookFinder.scala | 2 +- common/app/common/package.scala | 2 +- common/app/services/ConfigAgentTrait.scala | 2 +- facia/test/controllers/front/FrontHeadlineTest.scala | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/commercial/app/model/merchandise/books/BookFinder.scala b/commercial/app/model/merchandise/books/BookFinder.scala index 4c6560c509b9..9e05a840918a 100644 --- a/commercial/app/model/merchandise/books/BookFinder.scala +++ b/commercial/app/model/merchandise/books/BookFinder.scala @@ -1,12 +1,12 @@ package commercial.model.merchandise.books import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} -import akka.util.Timeout import commercial.model.feeds.{FeedParseException, FeedReadException, FeedReader, FeedRequest} import commercial.model.merchandise.Book import common.{Box, GuLogging} import conf.Configuration import org.apache.pekko.pattern.CircuitBreaker +import org.apache.pekko.util.Timeout import play.api.libs.json._ import play.api.libs.oauth.{ConsumerKey, OAuthCalculator, RequestToken} import play.api.libs.ws.{WSClient, WSSignatureCalculator} diff --git a/common/app/common/package.scala b/common/app/common/package.scala index e2783e6e1703..51f51aeb4341 100644 --- a/common/app/common/package.scala +++ b/common/app/common/package.scala @@ -1,7 +1,6 @@ package common import java.util.concurrent.TimeoutException -import akka.pattern.CircuitBreakerOpenException import com.gu.contentapi.client.model.ContentApiError import com.gu.contentapi.client.model.v1.ErrorResponse import conf.switches.Switch @@ -17,6 +16,7 @@ import play.twirl.api.Html import model.ApplicationContext import http.ResultWithPreconnectPreload import http.HttpPreconnections +import org.apache.pekko.pattern.CircuitBreakerOpenException import renderers.{DCRLocalConnectException, DCRTimeoutException} object `package` diff --git a/common/app/services/ConfigAgentTrait.scala b/common/app/services/ConfigAgentTrait.scala index 56a7f3901897..26d8cf02c615 100644 --- a/common/app/services/ConfigAgentTrait.scala +++ b/common/app/services/ConfigAgentTrait.scala @@ -1,6 +1,5 @@ package services -import akka.util.Timeout import app.LifecycleComponent import com.gu.facia.api.models.{Front, _} import com.gu.facia.client.ApiClient @@ -11,6 +10,7 @@ import conf.Configuration import fronts.FrontsApi import model.pressed.CollectionConfig import model.{ApplicationContext, FrontProperties, SeoDataJson} +import org.apache.pekko.util.Timeout import play.api.inject.ApplicationLifecycle import play.api.libs.json.Json diff --git a/facia/test/controllers/front/FrontHeadlineTest.scala b/facia/test/controllers/front/FrontHeadlineTest.scala index 2f432784324d..bb4b98beb9bc 100644 --- a/facia/test/controllers/front/FrontHeadlineTest.scala +++ b/facia/test/controllers/front/FrontHeadlineTest.scala @@ -1,11 +1,12 @@ package controllers.front -import akka.util.Timeout +import org.apache.pekko.util.Timeout import common.facia.FixtureBuilder import model.Cached.RevalidatableResult import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers import play.api.test.Helpers +import play.api.test.Helpers.defaultAwaitTimeout import scala.concurrent.duration._ import scala.concurrent.Future From e8051afce3b6f12d20af7c9fbe78bd1bccc224da Mon Sep 17 00:00:00 2001 From: DanielCliftonGuardian <110032454+DanielCliftonGuardian@users.noreply.github.com> Date: Mon, 11 Sep 2023 10:03:39 +0100 Subject: [PATCH 6/8] tidy, refactor --- commercial/app/model/merchandise/books/BookFinder.scala | 4 ++-- common/app/app/FrontendApplicationLoader.scala | 2 -- project/Dependencies.scala | 6 +++--- sport/app/cricket/feed/CricketThrottler.scala | 8 ++++---- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/commercial/app/model/merchandise/books/BookFinder.scala b/commercial/app/model/merchandise/books/BookFinder.scala index 9e05a840918a..95d4d7d9a066 100644 --- a/commercial/app/model/merchandise/books/BookFinder.scala +++ b/commercial/app/model/merchandise/books/BookFinder.scala @@ -1,12 +1,12 @@ package commercial.model.merchandise.books import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} +import org.apache.pekko.pattern.CircuitBreaker +import org.apache.pekko.util.Timeout import commercial.model.feeds.{FeedParseException, FeedReadException, FeedReader, FeedRequest} import commercial.model.merchandise.Book import common.{Box, GuLogging} import conf.Configuration -import org.apache.pekko.pattern.CircuitBreaker -import org.apache.pekko.util.Timeout import play.api.libs.json._ import play.api.libs.oauth.{ConsumerKey, OAuthCalculator, RequestToken} import play.api.libs.ws.{WSClient, WSSignatureCalculator} diff --git a/common/app/app/FrontendApplicationLoader.scala b/common/app/app/FrontendApplicationLoader.scala index f61406e670d5..359462e4f22f 100644 --- a/common/app/app/FrontendApplicationLoader.scala +++ b/common/app/app/FrontendApplicationLoader.scala @@ -37,8 +37,6 @@ trait FrontendComponents lazy val prefix = "/" -// implicit lazy val as = actorSystem - implicit val pekkoActorSystem: PekkoActorSystem = PekkoActorSystem.create() applicationLifecycle.addStopHook(() => { pekkoActorSystem.terminate() diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 034a276be43d..accb73cf1a0d 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -6,9 +6,6 @@ object Dependencies { // Once we're able to upgrade identityLibVersion to >=4.10 we should // remove the http4s-core dependency eviction below. (Unless we've // started needing it for something else in the meantime.) - val pekkoVersion = "1.0.1" - val pekkoActor = "org.apache.pekko" %% "pekko-actor" % pekkoVersion - val pekkoStream = "org.apache.pekko" %% "pekko-stream" % pekkoVersion val identityLibVersion = "3.255" val awsVersion = "1.12.205" val capiVersion = "19.4.0" @@ -75,6 +72,9 @@ object Dependencies { val jerseyClient = "com.sun.jersey" % "jersey-client" % jerseyVersion val w3cSac = "org.w3c.css" % "sac" % "1.3" val libPhoneNumber = "com.googlecode.libphonenumber" % "libphonenumber" % "8.10.0" + val pekkoVersion = "1.0.1" + val pekkoActor = "org.apache.pekko" %% "pekko-actor" % pekkoVersion + val pekkoStream = "org.apache.pekko" %% "pekko-stream" % pekkoVersion val logback2 = "net.logstash.logback" % "logstash-logback-encoder" % "4.6" // logback2 to prevent "error: reference to logback is ambiguous;" diff --git a/sport/app/cricket/feed/CricketThrottler.scala b/sport/app/cricket/feed/CricketThrottler.scala index c7036b5aeb33..381407e4e1c6 100644 --- a/sport/app/cricket/feed/CricketThrottler.scala +++ b/sport/app/cricket/feed/CricketThrottler.scala @@ -2,7 +2,7 @@ package cricket.feed import org.apache.pekko.NotUsed import org.apache.pekko.pattern.{ask, pipe} -import org.apache.pekko.stream.{CompletionStrategy, Materializer, OverflowStrategy, ThrottleMode} +import org.apache.pekko.stream.{CompletionStrategy, Materializer => PekkoMaterializer, OverflowStrategy, ThrottleMode} import java.util.concurrent.TimeUnit import org.apache.pekko.actor.{Actor, ActorRef, Props, ActorSystem => PekkoActorSystem} @@ -16,7 +16,7 @@ import scala.reflect.ClassTag case class CricketThrottledTask[+T](task: () => Future[T]) -class CricketThrottlerActor()(implicit materializer: Materializer) extends Actor { +class CricketThrottlerActor()(implicit pekkoMaterializer: PekkoMaterializer) extends Actor { import context.dispatcher private case class TaskWithSender[+T](sender: ActorRef, task: () => Future[T]) @@ -41,9 +41,9 @@ class CricketThrottlerActor()(implicit materializer: Materializer) extends Actor } } -class CricketThrottler(pekkoActorSystem: PekkoActorSystem, materializer: Materializer) { +class CricketThrottler(pekkoActorSystem: PekkoActorSystem, pekkoMaterializer: PekkoMaterializer) { private val cricketThrottlerActor: ActorRef = - pekkoActorSystem.actorOf(Props(new CricketThrottlerActor()(materializer))) + pekkoActorSystem.actorOf(Props(new CricketThrottlerActor()(pekkoMaterializer))) def throttle[T](task: () => Future[T])(implicit ec: ExecutionContext, tag: ClassTag[T]): Future[T] = { // we have a long timeout to allow for the large number of requests to be made when the app starts up, at 1s/request From 9f52e68f6d40bcb56bef1099d5f6515651c59391 Mon Sep 17 00:00:00 2001 From: DanielCliftonGuardian <110032454+DanielCliftonGuardian@users.noreply.github.com> Date: Mon, 11 Sep 2023 13:47:14 +0100 Subject: [PATCH 7/8] standardise naming --- .../services/NewspaperBooksAndSectionsAutoRefresh.scala | 4 ++-- common/app/common/AutoRefresh.scala | 6 +++--- common/app/common/Logback/KinesisAdapter.scala | 8 ++++---- common/app/common/akka.scala | 8 ++++---- common/app/concurrent/BlockingOperations.scala | 6 +++--- common/app/renderers/DotcomRenderingService.scala | 4 ++-- common/app/services/indexAutoRefreshes.scala | 4 ++-- dev-build/app/AppLoader.scala | 4 ++-- onward/app/business/StocksDataLifecycle.scala | 4 ++-- onward/app/feed/MostPopularSocialAutoRefresh.scala | 4 ++-- onward/app/weather/WeatherApi.scala | 6 +++--- sport/app/cricket/feed/cricketPaFeed.scala | 6 +++--- 12 files changed, 32 insertions(+), 32 deletions(-) diff --git a/article/app/services/NewspaperBooksAndSectionsAutoRefresh.scala b/article/app/services/NewspaperBooksAndSectionsAutoRefresh.scala index a50b1995f5dd..a39e359bf310 100644 --- a/article/app/services/NewspaperBooksAndSectionsAutoRefresh.scala +++ b/article/app/services/NewspaperBooksAndSectionsAutoRefresh.scala @@ -1,6 +1,6 @@ package services -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import app.LifecycleComponent import common.AutoRefresh import model.{TagDefinition, TagIndexListings} @@ -12,7 +12,7 @@ import scala.language.postfixOps class NewspaperBooksAndSectionsAutoRefresh( newspaperBookSectionTagAgent: NewspaperBookSectionTagAgent, newspaperBookTagAgent: NewspaperBookTagAgent, -)(implicit actorSystem: ActorSystem, executionContext: ExecutionContext) +)(implicit pekkoActorSystem: PekkoActorSystem, executionContext: ExecutionContext) extends LifecycleComponent { override def start(): Unit = { newspaperBookTagAgent.start() diff --git a/common/app/common/AutoRefresh.scala b/common/app/common/AutoRefresh.scala index ad2f934d97ac..86b5fd57ba54 100644 --- a/common/app/common/AutoRefresh.scala +++ b/common/app/common/AutoRefresh.scala @@ -1,7 +1,7 @@ package common import scala.concurrent.duration.FiniteDuration -import org.apache.pekko.actor.{ActorSystem, Cancellable} +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem, Cancellable} import scala.concurrent.{ExecutionContext, Future} import scala.util.{Failure, Success} @@ -35,9 +35,9 @@ abstract class AutoRefresh[A](initialDelay: FiniteDuration, interval: FiniteDura } } - final def start()(implicit actorSystem: ActorSystem, executionContext: ExecutionContext): Unit = { + final def start()(implicit pekkoActorSystem: PekkoActorSystem, executionContext: ExecutionContext): Unit = { log.info(s"Starting refresh cycle after $initialDelay repeatedly over $interval delay") - val cancellable = actorSystem.scheduler.scheduleWithFixedDelay(initialDelay, interval) { new Task() } + val cancellable = pekkoActorSystem.scheduler.scheduleWithFixedDelay(initialDelay, interval) { new Task() } subscription = Some(cancellable) } diff --git a/common/app/common/Logback/KinesisAdapter.scala b/common/app/common/Logback/KinesisAdapter.scala index afa0f4e1b913..5db5d06246f5 100644 --- a/common/app/common/Logback/KinesisAdapter.scala +++ b/common/app/common/Logback/KinesisAdapter.scala @@ -1,7 +1,7 @@ package common.Logback import java.util.concurrent.ThreadPoolExecutor -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import org.apache.pekko.dispatch.MessageDispatcher import org.apache.pekko.pattern.CircuitBreaker import ch.qos.logback.classic.spi.ILoggingEvent @@ -16,8 +16,8 @@ import scala.concurrent.Future import scala.annotation.nowarn // LogbackOperationsPool must be wired as a singleton -class LogbackOperationsPool(val actorSystem: ActorSystem) { - val logbackOperations: MessageDispatcher = actorSystem.dispatchers.lookup("akka.logback-operations") +class LogbackOperationsPool(val pekkoActorSystem: PekkoActorSystem) { + val logbackOperations: MessageDispatcher = pekkoActorSystem.dispatchers.lookup("akka.logback-operations") } // The KinesisAppender[ILoggingEvent] blocks logging operations on putMessage. This overrides the KinesisAppender api, executing putMessage in an @@ -25,7 +25,7 @@ class LogbackOperationsPool(val actorSystem: ActorSystem) { class SafeBlockingKinesisAppender(logbackOperations: LogbackOperationsPool) extends KinesisAppender[ILoggingEvent] { private val breaker = new CircuitBreaker( - logbackOperations.actorSystem.scheduler, + logbackOperations.pekkoActorSystem.scheduler, maxFailures = 1, callTimeout = 1.seconds, resetTimeout = 10.seconds, diff --git a/common/app/common/akka.scala b/common/app/common/akka.scala index 5908d9ea277d..54ff88dc5012 100644 --- a/common/app/common/akka.scala +++ b/common/app/common/akka.scala @@ -4,10 +4,10 @@ import scala.concurrent.duration._ import play.api.{Environment => PlayEnv, Mode} import scala.concurrent.ExecutionContext -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} -class AkkaAsync(env: PlayEnv, actorSystem: ActorSystem) { - implicit val ec: ExecutionContext = actorSystem.dispatcher +class AkkaAsync(env: PlayEnv, pekkoActorSystem: PekkoActorSystem) { + implicit val ec: ExecutionContext = pekkoActorSystem.dispatcher // "apply" isn't expressive and doesn't explain what it does. // If you were considering using that function, use after1s instead as it doesn't leave any ambiguity. @@ -20,6 +20,6 @@ class AkkaAsync(env: PlayEnv, actorSystem: ActorSystem) { // want to check in def after(delay: FiniteDuration)(body: => Unit): Unit = if (env.mode != Mode.Test) { - actorSystem.scheduler.scheduleOnce(delay)(body) + pekkoActorSystem.scheduler.scheduleOnce(delay)(body) } } diff --git a/common/app/concurrent/BlockingOperations.scala b/common/app/concurrent/BlockingOperations.scala index bb4865ed7a94..a3582ba24c90 100644 --- a/common/app/concurrent/BlockingOperations.scala +++ b/common/app/concurrent/BlockingOperations.scala @@ -1,12 +1,12 @@ package concurrent -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import org.apache.pekko.dispatch.MessageDispatcher import scala.concurrent.Future -class BlockingOperations(actorSystem: ActorSystem) { - private val blockingOperations: MessageDispatcher = actorSystem.dispatchers.lookup("akka.blocking-operations") +class BlockingOperations(pekkoActorSystem: PekkoActorSystem) { + private val blockingOperations: MessageDispatcher = pekkoActorSystem.dispatchers.lookup("akka.blocking-operations") def executeBlocking[T](block: => T): Future[T] = { Future(block)(blockingOperations) diff --git a/common/app/renderers/DotcomRenderingService.scala b/common/app/renderers/DotcomRenderingService.scala index b3be8be5d322..1067eaa023c8 100644 --- a/common/app/renderers/DotcomRenderingService.scala +++ b/common/app/renderers/DotcomRenderingService.scala @@ -1,6 +1,6 @@ package renderers -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import com.gu.contentapi.client.model.v1.{Block, Blocks, Content} import common.{DCRMetrics, GuLogging} import concurrent.CircuitBreakerRegistry @@ -49,7 +49,7 @@ class DotcomRenderingService extends GuLogging with ResultWithPreconnectPreload private[this] val circuitBreaker = CircuitBreakerRegistry.withConfig( name = "dotcom-rendering-client", - system = ActorSystem("dotcom-rendering-client-circuit-breaker"), + system = PekkoActorSystem("dotcom-rendering-client-circuit-breaker"), maxFailures = Configuration.rendering.circuitBreakerMaxFailures, callTimeout = Configuration.rendering.timeout.plus(200.millis), resetTimeout = Configuration.rendering.timeout * 4, diff --git a/common/app/services/indexAutoRefreshes.scala b/common/app/services/indexAutoRefreshes.scala index b4160d1c3241..55e3b5791bfc 100644 --- a/common/app/services/indexAutoRefreshes.scala +++ b/common/app/services/indexAutoRefreshes.scala @@ -1,6 +1,6 @@ package services -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import app.LifecycleComponent import common.AutoRefresh import model.TagIndexListings @@ -9,7 +9,7 @@ import scala.concurrent.duration._ import scala.concurrent.{ExecutionContext, Future, blocking} import scala.language.postfixOps -class IndexListingsLifecycle(implicit actorSystem: ActorSystem, executionContext: ExecutionContext) +class IndexListingsLifecycle(implicit pekkoActorSystem: PekkoActorSystem, executionContext: ExecutionContext) extends LifecycleComponent { override def start(): Unit = { KeywordSectionIndexAutoRefresh.start() diff --git a/dev-build/app/AppLoader.scala b/dev-build/app/AppLoader.scala index d70f447cfd9b..0ebec672af6b 100644 --- a/dev-build/app/AppLoader.scala +++ b/dev-build/app/AppLoader.scala @@ -1,7 +1,7 @@ import _root_.commercial.CommercialLifecycle import _root_.commercial.controllers.CommercialControllers import _root_.commercial.targeting.TargetingLifecycle -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import agents.MostViewedAgent import app.{FrontendApplicationLoader, FrontendComponents, LifecycleComponent} import business.StocksDataLifecycle @@ -90,7 +90,7 @@ trait AppComponents override lazy val optionalDevContext = new OptionalDevContext(devContext) override lazy val sourceMapper = devContext.map(_.sourceMapper) - def actorSystem: ActorSystem + def pekkoActorSystem: PekkoActorSystem override def router: Router = wire[Routes] override def appIdentity: ApplicationIdentity = ApplicationIdentity("dev-build") diff --git a/onward/app/business/StocksDataLifecycle.scala b/onward/app/business/StocksDataLifecycle.scala index 62868fddc132..b876f79221ab 100644 --- a/onward/app/business/StocksDataLifecycle.scala +++ b/onward/app/business/StocksDataLifecycle.scala @@ -1,6 +1,6 @@ package business -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import app.LifecycleComponent import play.api.inject.ApplicationLifecycle @@ -8,7 +8,7 @@ import scala.concurrent.{ExecutionContext, Future} class StocksDataLifecycle(appLifecycle: ApplicationLifecycle, stocksData: StocksData)(implicit ec: ExecutionContext, - actorSystem: ActorSystem, + pekkoActorSystem: PekkoActorSystem, ) extends LifecycleComponent { appLifecycle.addStopHook { () => diff --git a/onward/app/feed/MostPopularSocialAutoRefresh.scala b/onward/app/feed/MostPopularSocialAutoRefresh.scala index 67b521cf00f0..980d7ed32a61 100644 --- a/onward/app/feed/MostPopularSocialAutoRefresh.scala +++ b/onward/app/feed/MostPopularSocialAutoRefresh.scala @@ -1,6 +1,6 @@ package feed -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import app.LifecycleComponent import common.AutoRefresh import play.api.inject.ApplicationLifecycle @@ -24,7 +24,7 @@ class MostPopularSocialAutoRefresh(ophanApi: OphanApi) extends AutoRefresh[MostR class MostPopularFacebookAutoRefreshLifecycle( appLifeCycle: ApplicationLifecycle, mostPopularSocialAutoRefresh: MostPopularSocialAutoRefresh, -)(implicit ec: ExecutionContext, actorSystem: ActorSystem) +)(implicit ec: ExecutionContext, pekkoActorSystem: PekkoActorSystem) extends LifecycleComponent { appLifeCycle.addStopHook { () => diff --git a/onward/app/weather/WeatherApi.scala b/onward/app/weather/WeatherApi.scala index 7b8c6f79ec1c..d4e2e5d37d23 100644 --- a/onward/app/weather/WeatherApi.scala +++ b/onward/app/weather/WeatherApi.scala @@ -2,7 +2,7 @@ package weather import java.net.{URI, URLEncoder} import java.util.concurrent.TimeoutException -import org.apache.pekko.actor.{ActorSystem, Scheduler} +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem, Scheduler} import common.{GuLogging, ResourcesHelper} import conf.Configuration import play.api.libs.json.{JsValue, Json} @@ -20,7 +20,7 @@ import org.apache.pekko.pattern.after import scala.concurrent.{ExecutionContext, Future} import scala.util.control.NonFatal -class WeatherApi(wsClient: WSClient, context: ApplicationContext, actorSystem: ActorSystem)(implicit +class WeatherApi(wsClient: WSClient, context: ApplicationContext, pekkoActorSystem: PekkoActorSystem)(implicit ec: ExecutionContext, ) extends ResourcesHelper with GuLogging { @@ -66,7 +66,7 @@ class WeatherApi(wsClient: WSClient, context: ApplicationContext, actorSystem: A val weatherApiResponse: Future[JsValue] = WeatherApi.retryWeatherRequest( () => getJsonRequest(url), requestRetryDelay, - actorSystem.scheduler, + pekkoActorSystem.scheduler, requestRetryMax, ) weatherApiResponse.failed.foreach { diff --git a/sport/app/cricket/feed/cricketPaFeed.scala b/sport/app/cricket/feed/cricketPaFeed.scala index cc190f714835..a2f918fb56f4 100644 --- a/sport/app/cricket/feed/cricketPaFeed.scala +++ b/sport/app/cricket/feed/cricketPaFeed.scala @@ -1,6 +1,6 @@ package conf.cricketPa -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import common.Chronos import common.GuLogging import cricket.feed.CricketThrottler @@ -18,12 +18,12 @@ object PaFeed { val dateFormat = Chronos.dateFormatter("yyyy-MM-dd", ZoneId.of("UTC")) } -class PaFeed(wsClient: WSClient, actorSystem: ActorSystem, materializer: Materializer) extends GuLogging { +class PaFeed(wsClient: WSClient, pekkoActorSystem: PekkoActorSystem, materializer: Materializer) extends GuLogging { private val paEndpoint = "https://cricket-api.guardianapis.com/v1" private val credentials = conf.SportConfiguration.pa.cricketKey.map { ("Apikey", _) } private val xmlContentType = ("Accept", "application/xml") - private implicit val throttler = new CricketThrottler(actorSystem, materializer) + private implicit val throttler = new CricketThrottler(pekkoActorSystem, materializer) private def getMatchPaResponse(apiMethod: String)(implicit executionContext: ExecutionContext): Future[String] = { credentials From cd8bcc35ca67adce9d76a441a9419ed9492aa80e Mon Sep 17 00:00:00 2001 From: DanielCliftonGuardian <110032454+DanielCliftonGuardian@users.noreply.github.com> Date: Tue, 12 Sep 2023 12:06:08 +0100 Subject: [PATCH 8/8] naming --- .../services/ParameterStoreServiceTest.scala | 6 +++--- .../concurrent/CircuitBreakerRegistry.scala | 4 ++-- common/app/contentapi/ContentApiClient.scala | 4 ++-- .../concurrent/BlockingOperationsTest.scala | 4 ++-- common/test/package.scala | 7 ++----- facia/test/FaciaControllerTest.scala | 19 ++++++++----------- facia/test/FaciaMetaDataTest.scala | 6 ++---- onward/test/weather/WeatherApiTest.scala | 4 ++-- 8 files changed, 23 insertions(+), 31 deletions(-) diff --git a/admin/test/services/ParameterStoreServiceTest.scala b/admin/test/services/ParameterStoreServiceTest.scala index 3488911ba0f3..3dad5a5db45e 100644 --- a/admin/test/services/ParameterStoreServiceTest.scala +++ b/admin/test/services/ParameterStoreServiceTest.scala @@ -1,6 +1,6 @@ package services -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import concurrent.BlockingOperations import org.scalatest.concurrent.ScalaFutures import org.mockito.Mockito._ @@ -11,8 +11,8 @@ import org.scalatestplus.mockito.MockitoSugar class ParameterStoreServiceTest extends AnyFlatSpec with ScalaFutures with Matchers with MockitoSugar { "findParameterBySubstring" should "retrieve a parameter from the parameter store by substring" in { - val actorSystem = ActorSystem() - val blockingOperations = new BlockingOperations(actorSystem) + val pekkoActorSystem = PekkoActorSystem() + val blockingOperations = new BlockingOperations(pekkoActorSystem) val parameterStore = mock[ParameterStore] when(parameterStore.getPath("/frontend", isRecursiveSearch = true)) thenReturn Map( diff --git a/common/app/concurrent/CircuitBreakerRegistry.scala b/common/app/concurrent/CircuitBreakerRegistry.scala index e88a2d98042c..b33d63dcb80f 100644 --- a/common/app/concurrent/CircuitBreakerRegistry.scala +++ b/common/app/concurrent/CircuitBreakerRegistry.scala @@ -1,6 +1,6 @@ package concurrent -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import org.apache.pekko.pattern.CircuitBreaker import common.GuLogging @@ -11,7 +11,7 @@ object CircuitBreakerRegistry extends GuLogging { def withConfig( name: String, - system: ActorSystem, + system: PekkoActorSystem, maxFailures: Int, callTimeout: FiniteDuration, resetTimeout: FiniteDuration, diff --git a/common/app/contentapi/ContentApiClient.scala b/common/app/contentapi/ContentApiClient.scala index 9b4ab17fb4da..7f6a927054de 100644 --- a/common/app/contentapi/ContentApiClient.scala +++ b/common/app/contentapi/ContentApiClient.scala @@ -2,7 +2,7 @@ package contentapi import java.util.concurrent.TimeUnit -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import com.github.nscala_time.time.Implicits._ import com.gu.contentapi.client.model._ import com.gu.contentapi.client.model.v1.{Edition => _, _} @@ -136,7 +136,7 @@ final case class CircuitBreakingContentApiClient( private[this] val circuitBreaker = CircuitBreakerRegistry.withConfig( name = "content-api-client", - system = ActorSystem("content-api-client-circuit-breaker"), + system = PekkoActorSystem("content-api-client-circuit-breaker"), maxFailures = contentApi.circuitBreakerErrorThreshold, callTimeout = contentApi.timeout + Duration .create(400, MILLISECONDS), // +400 to differentiate between circuit breaker and capi timeouts diff --git a/common/test/concurrent/BlockingOperationsTest.scala b/common/test/concurrent/BlockingOperationsTest.scala index 7928ace705a6..17f5d03a880f 100644 --- a/common/test/concurrent/BlockingOperationsTest.scala +++ b/common/test/concurrent/BlockingOperationsTest.scala @@ -1,12 +1,12 @@ package concurrent -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import org.scalatest.concurrent.ScalaFutures import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers class BlockingOperationsTest extends AnyFlatSpec with Matchers with ScalaFutures { - val system = ActorSystem() + val system = PekkoActorSystem() "BlockingOperations" should "execute blocks in a thread pool" in { val blockingOperaitons = new BlockingOperations(system) diff --git a/common/test/package.scala b/common/test/package.scala index 5fbf82931da2..516ef775937f 100644 --- a/common/test/package.scala +++ b/common/test/package.scala @@ -1,14 +1,9 @@ package test -import org.apache.pekko.actor.ActorSystem - -import java.io.File -import java.net.URL import akka.stream.Materializer import com.gargoylesoftware.htmlunit.html.HtmlPage import com.gargoylesoftware.htmlunit.{BrowserVersion, WebClient} import common.Lazy -import concurrent.BlockingOperations import contentapi._ import model.{ApplicationContext, ApplicationIdentity, PressedPage, PressedPageType} import org.openqa.selenium.htmlunit.HtmlUnitDriver @@ -26,6 +21,8 @@ import play.filters.csrf.{CSRFAddToken, CSRFCheck, CSRFConfig} import recorder.{ContentApiHttpRecorder, HttpRecorder} import services.fronts.FrontJsonFapiLive +import java.io.File +import java.net.URL import scala.concurrent.{ExecutionContext, Future} import scala.io.Codec.UTF8 import scala.util.{Failure, Success, Try} diff --git a/facia/test/FaciaControllerTest.scala b/facia/test/FaciaControllerTest.scala index 3b8fd8118f7b..c51b683b3728 100644 --- a/facia/test/FaciaControllerTest.scala +++ b/facia/test/FaciaControllerTest.scala @@ -1,29 +1,26 @@ package test import agents.{DeeplyReadAgent, MostViewedAgent} -import org.apache.pekko.actor.ActorSystem import com.fasterxml.jackson.core.JsonParseException import com.gu.facia.client.models.{ConfigJson, FrontJson} import common.editions.{Uk, Us} -import implicits.FakeRequests -import concurrent.BlockingOperations -import play.api.libs.json.JsArray -import play.api.test._ -import play.api.test.Helpers._ -import services.{ConfigAgent, OphanApi} -import org.scalatest._ import controllers.FaciaControllerImpl import helpers.FaciaTestData +import implicits.FakeRequests +import org.mockito.Matchers.{any, anyString} import org.mockito.Mockito.when -import org.mockito.Matchers.any -import org.mockito.Matchers.anyString +import org.scalatest._ import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers import org.scalatestplus.mockito.MockitoSugar +import play.api.libs.json.JsArray +import play.api.libs.ws.{WSClient, WSRequest, WSResponse} +import play.api.test.Helpers._ +import play.api.test._ +import services.{ConfigAgent, OphanApi} import scala.concurrent.duration._ import scala.concurrent.{Await, Future} -import play.api.libs.ws.{WSClient, WSRequest, WSResponse} @DoNotDiscover class FaciaControllerTest extends AnyFlatSpec diff --git a/facia/test/FaciaMetaDataTest.scala b/facia/test/FaciaMetaDataTest.scala index 37dc68c8070d..0de54d95c8df 100644 --- a/facia/test/FaciaMetaDataTest.scala +++ b/facia/test/FaciaMetaDataTest.scala @@ -1,9 +1,7 @@ package metadata import agents.{DeeplyReadAgent, MostViewedAgent} -import org.apache.pekko.actor.ActorSystem import com.gu.facia.client.models.{ConfigJson, FrontJson} -import concurrent.BlockingOperations import conf.Configuration import conf.switches.Switches.DCRFronts import controllers.FaciaControllerImpl @@ -15,10 +13,10 @@ import org.scalatestplus.mockito.MockitoSugar import play.api.libs.json._ import play.api.test.Helpers._ import services.{ConfigAgent, OphanApi} +import test._ -import scala.concurrent.duration._ import scala.concurrent.Await -import test._ +import scala.concurrent.duration._ @DoNotDiscover class FaciaMetaDataTest extends AnyFlatSpec diff --git a/onward/test/weather/WeatherApiTest.scala b/onward/test/weather/WeatherApiTest.scala index db76fc88dbc9..24f9b8d544f4 100644 --- a/onward/test/weather/WeatherApiTest.scala +++ b/onward/test/weather/WeatherApiTest.scala @@ -1,6 +1,6 @@ package weather -import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} import org.scalatest.concurrent.ScalaFutures import play.api.libs.json.{JsString, JsValue} import org.mockito.Mockito._ @@ -14,7 +14,7 @@ import scala.concurrent.Future import scala.language.postfixOps class WeatherApiTest extends AnyFlatSpec with ScalaFutures with Matchers with MockitoSugar { - val actorSystem = ActorSystem() + val actorSystem = PekkoActorSystem() "retryWeatherRequest" should "return for a successful future" in { val jsValue = JsString("Test")