Skip to content

Commit

Permalink
remove the 'facia press queue' since the queue (in frontend account) …
Browse files Browse the repository at this point in the history
…is now subscribed to the SNS topic instead
  • Loading branch information
twrichards committed Jan 4, 2024
1 parent 57f4cee commit c151c2a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 68 deletions.
5 changes: 2 additions & 3 deletions app/Components.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ class AppComponents(context: Context, val config: ApplicationConfiguration)
val containers = new Containers(fixedContainers)
val containerService = new ContainerService(containers)
val collectionService = new CollectionService(frontsApi, containerService)
val faciaPressQueue = new FaciaPressQueue(config)
val faciaPressTopic = new FaciaPressTopic(config)
val faciaPress = new FaciaPress(faciaPressQueue, faciaPressTopic, configAgent)
val faciaPress = new FaciaPress(faciaPressTopic, configAgent)
val updateActions = new UpdateActions(faciaApiIO, frontsApi, config, configAgent, structuredLogger)
val updateManager = new UpdateManager(updateActions, configAgent, s3FrontsApi)
val cloudwatch = new CloudWatch(config, awsEndpoints)
Expand All @@ -93,7 +92,7 @@ class AppComponents(context: Context, val config: ApplicationConfiguration)
val defaults = new DefaultsController(acl, isDev, this)
val faciaCapiProxy = new FaciaContentApiProxy(capi, this)
val faciaTool = new FaciaToolController(acl, frontsApi, collectionService, faciaApiIO, updateActions, breakingNewsUpdate,
structuredLogger, faciaPress, faciaPressQueue, faciaPressTopic, configAgent, s3FrontsApi, this)
structuredLogger, faciaPress, faciaPressTopic, configAgent, s3FrontsApi, this)
val front = new FrontController(acl, structuredLogger, updateManager, press, this)
val pandaAuth = new PandaAuthController(this)
val status = new StatusController(this)
Expand Down
1 change: 0 additions & 1 deletion app/conf/Configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ class ApplicationConfiguration(val playConfiguration: PlayConfiguration, val isP

object faciatool {
lazy val breakingNewsFront = "breaking-news"
lazy val frontPressToolQueue = getString("frontpress.sqs.tool_queue_url")
lazy val frontPressToolTopic = getString("faciatool.sns.tool_topic_arn")
lazy val publishEventsQueue = getMandatoryString("publish_events.queue_url")
lazy val showTestContainers = getBoolean("faciatool.show_test_containers").getOrElse(false)
Expand Down
36 changes: 17 additions & 19 deletions app/controllers/FaciaToolController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ import scala.concurrent.{ExecutionContext, Future}
import permissions.CollectionPermissions

class FaciaToolController(
val acl: Acl,
val frontsApi: FrontsApi,
val collectionService: CollectionService,
val faciaApiIO: FaciaApiIO,
val updateActions: UpdateActions,
breakingNewsUpdate: BreakingNewsUpdate,
val structuredLogger: StructuredLogger,
val faciaPress: FaciaPress,
val faciaPressQueue: FaciaPressQueue,
val FaciaPressTopic: FaciaPressTopic,
val configAgent: ConfigAgent,
val s3FrontsApi: S3FrontsApi,
val deps: BaseFaciaControllerComponents
)(implicit ec: ExecutionContext)
extends BaseFaciaController(deps) with BreakingNewsEditCollectionsCheck with ModifyCollectionsPermissionsCheck with Logging {
val acl: Acl,
val frontsApi: FrontsApi,
val collectionService: CollectionService,
val faciaApiIO: FaciaApiIO,
val updateActions: UpdateActions,
breakingNewsUpdate: BreakingNewsUpdate,
val structuredLogger: StructuredLogger,
val faciaPress: FaciaPress,
val faciaPressTopic: FaciaPressTopic,
val configAgent: ConfigAgent,
val s3FrontsApi: S3FrontsApi,
val deps: BaseFaciaControllerComponents
)(
implicit ec: ExecutionContext
) extends BaseFaciaController(deps) with BreakingNewsEditCollectionsCheck with ModifyCollectionsPermissionsCheck with Logging {

private val collectionPermissions = CollectionPermissions(configAgent.get)

Expand Down Expand Up @@ -246,14 +246,12 @@ class FaciaToolController(
}

def pressLivePath(path: String) = AccessAPIAuthAction { request =>
faciaPressQueue.enqueue(PressJob(FrontPath(path), Live, forceConfigUpdate = Option(true)))
FaciaPressTopic.publish(PressJob(FrontPath(path), Live, forceConfigUpdate = Option(true)))
faciaPressTopic.publish(PressJob(FrontPath(path), Live, forceConfigUpdate = Option(true)))
NoCache(Ok)
}

def pressDraftPath(path: String) = AccessAPIAuthAction { request =>
faciaPressQueue.enqueue(PressJob(FrontPath(path), Draft, forceConfigUpdate = Option(true)))
FaciaPressTopic.publish(PressJob(FrontPath(path), Draft, forceConfigUpdate = Option(true)))
faciaPressTopic.publish(PressJob(FrontPath(path), Draft, forceConfigUpdate = Option(true)))
NoCache(Ok)
}

Expand Down
56 changes: 16 additions & 40 deletions app/services/FaciaPress.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,6 @@ object PressCommand {
def forOneId(id: String): PressCommand = PressCommand(Set(id))
}

class FaciaPressQueue(val config: ApplicationConfiguration) {
val maybeQueue = config.faciatool.frontPressToolQueue map { queueUrl =>
val credentials = config.aws.frontendAccountCredentials
JsonMessageQueue[PressJob](
AmazonSQSAsyncClientBuilder.standard()
.withCredentials(credentials)
.withRegion(Regions.EU_WEST_1).build(),
queueUrl
)
}

def enqueue(job: PressJob): Future[SendMessageResult] = {
maybeQueue match {
case Some(queue) =>
queue.send(job)

case None =>
Future.failed(new RuntimeException("`facia.press.queue_url` property not in config, could not enqueue job."))
}
}
}

class FaciaPressTopic(val config: ApplicationConfiguration) {
val maybeTopic = config.faciatool.frontPressToolTopic map { topicArn =>
val credentials = config.aws.cmsFrontsAccountCredentials
Expand All @@ -73,37 +51,35 @@ class FaciaPressTopic(val config: ApplicationConfiguration) {

}

class FaciaPress(val faciaPressQueue: FaciaPressQueue, val faciaPressTopic: FaciaPressTopic, val configAgent: ConfigAgent) extends Logging {
def press(pressCommand: PressCommand): Future[List[SendMessageResult]] = {
class FaciaPress(val faciaPressTopic: FaciaPressTopic, val configAgent: ConfigAgent) extends Logging {
def press(pressCommand: PressCommand): Future[List[PublishResult]] = {
configAgent.refreshAndReturn() flatMap { _ =>
val paths: Set[String] = for {
id <- pressCommand.collectionIds
path <- configAgent.getConfigsUsingCollectionId(id)
} yield path

def sendEvents(pressType: PressType) = {
val result = Future.traverse(paths.filter(_ => pressType match {
def sendEvents(pressType: PressType) = Future.traverse(
paths.filter(_ => pressType match {
case Live => pressCommand.live
case Draft => pressCommand.draft
})) { path =>
})
) { path =>
val event = PressJob(FrontPath(path), pressType, forceConfigUpdate = pressCommand.forceConfigUpdate)

faciaPressTopic.publish(event).onComplete { // fire & forget (but log)
case Failure(error) => logger.error(s"Error publishing to the SNS topic, $pressType event: $event", error)
case Success(_) => logger.info(s"Published to the SNS topic, $pressType event: $event")
val publishResultFuture = faciaPressTopic.publish(event)

publishResultFuture.onComplete {
case Failure(error) =>
logger.error(s"Error publishing to the SNS topic, $pressType event: $event", error)
EnqueuePressFailure.increment()
case Success(_) =>
logger.info(s"Published to the SNS topic, $pressType event: $event")
EnqueuePressSuccess.increment()
}

faciaPressQueue.enqueue(event)
}
result.onComplete {
case Failure(error) =>
EnqueuePressFailure.increment()
logger.error(s"Error manually pressing $pressType collection through update from tool", error)
case Success(_) =>
EnqueuePressSuccess.increment()
publishResultFuture
}
result
}

for {
live <- sendEvents(Live)
Expand Down
5 changes: 0 additions & 5 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ PROD {
permissions.cache: "permissions-cache/PROD"
}

frontpress.sqs.tool_queue_url="https://sqs.eu-west-1.amazonaws.com/642631414762/frontend-CODE-FrontPressToolJobQueue-MY0QBVOOIECN"
PROD {
frontpress.sqs.tool_queue_url="https://sqs.eu-west-1.amazonaws.com/642631414762/frontend-PROD-FrontPressToolJobQueue-1V3225WE1LWQI"
}

publish_events.queue_url="https://sqs.eu-west-1.amazonaws.com/163592447864/publish-events-CODE"
PROD {
publish_events.queue_url="https://sqs.eu-west-1.amazonaws.com/163592447864/publish-events-PROD"
Expand Down

0 comments on commit c151c2a

Please sign in to comment.