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 8, 2024
1 parent 820018f commit aaae1e6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 72 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Run `yarn test` in `fronts-client` folder. See [fronts-client](/fronts-client) f

### Pressing fronts
- Before fronts can appear on site, they have to be pressed by Facia-Press which lives on the frontend account.
- The fronts tool sends events to an sqs queue which Facia-Press listens. You can read more about Facia-Press [here](https://github.com/guardian/frontend/blob/ad74a1da567f047b7b824650e6e1be0f0262952b/docs/02-architecture/01-applications-architecture.md).
- The fronts tool sends events to an SNS topic, which is subscribed to by a queue (in frontend account) to which Facia-Press listens. You can read more about Facia-Press [here](https://github.com/guardian/frontend/blob/ad74a1da567f047b7b824650e6e1be0f0262952b/docs/02-architecture/01-applications-architecture.md).

- If you are adding a new kind of content to a front or changing the front configuration, you should check that the front can still be pressed.

Expand All @@ -57,9 +57,8 @@ Run `yarn test` in `fronts-client` folder. See [fronts-client](/fronts-client) f
- You can remove this property from the front in the fronts config page.
- Select the front your are trying to view on the config page, click on the edit-metadata link, and deselect the `is hidden`-property.

- If you are developing locally and do not have frontend credentials from janus, the fronts tool won't have permissions to push events to the sqs queue that Facia-Press reads from. To test that a front is pressed, you will have to deploy your changes to code, and test the code from there.


- Since the SNS topic lives in the fronts account, CODE fronts should be pressed automatically when running locally.
-
## Different tools in this codebase

### The Fronts Tool
Expand Down
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 aaae1e6

Please sign in to comment.