Skip to content

Commit

Permalink
Commercial bundle updater 0% test (#27578)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakeii authored Dec 23, 2024
1 parent c00c6f7 commit 2a8e447
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 96 deletions.
91 changes: 0 additions & 91 deletions .github/workflows/commercial-bundle-bump.yml

This file was deleted.

36 changes: 36 additions & 0 deletions common/app/common/CommercialBundle.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package common

import scala.concurrent.duration._
import org.joda.time.Instant
import conf.Configuration
import services.ParameterStore

object CommercialBundle {
import GuardianConfiguration._

private lazy val parameterStore = new ParameterStore(Environment.awsRegion)

private val cacheDuration: FiniteDuration = 1.minute
private val stage = Environment.stage.toLowerCase()
private val bundlePathKey = s"/frontend/$stage/commercial.bundlePath"

// when running locally Configuration.assets.path is set to "assets/" to serve local assets, but the commercial bundle no longer lives there, so we need to override it
private val basePath =
if (stage == "dev") "https://assets.guim.co.uk/" else Configuration.assets.path

private var cachedBundlePath: String = bundlePathFromParameterStore
private var cachedTimestamp: Instant = Instant.now()

private def bundlePathFromParameterStore: String = parameterStore.get(bundlePathKey)

private def bundlePath: String = {
if (Instant.now().isAfter(cachedTimestamp.plus(cacheDuration.toMillis))) {
cachedBundlePath = bundlePathFromParameterStore
cachedTimestamp = Instant.now()
}

cachedBundlePath
}

def bundleUrl: String = s"$basePath$bundlePath"
}
10 changes: 10 additions & 0 deletions common/app/experiments/Experiments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object ActiveExperiments extends ExperimentsDefinition {
override val allExperiments: Set[Experiment] =
Set(
EuropeBetaFront,
CommercialBundleUpdater,
DarkModeWeb,
)
implicit val canCheckExperiment: CanCheckExperiment = new CanCheckExperiment(this)
Expand All @@ -38,3 +39,12 @@ object DarkModeWeb
sellByDate = LocalDate.of(2025, 1, 30),
participationGroup = Perc0D,
)

object CommercialBundleUpdater
extends Experiment(
name = "commercial-bundle-updater",
description = "Enable the commercial bundle updater",
owners = Seq(Owner.withGithub("jakeii")),
sellByDate = LocalDate.of(2025, 1, 30),
participationGroup = Perc0B,
)
15 changes: 10 additions & 5 deletions common/app/views/support/JavaScriptPage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import model.IpsosTags.getScriptTag
import model.dotcomrendering.DotcomRenderingUtils.assetURL
import play.api.mvc.RequestHeader
import views.support.Commercial.isAdFree
import common.CommercialBundle
import experiments.{ActiveExperiments, CommercialBundleUpdater}

object JavaScriptPage {

Expand Down Expand Up @@ -70,10 +72,13 @@ object JavaScriptPage {

val ipsos = if (page.metadata.isFront) getScriptTag(page.metadata.id) else getScriptTag(page.metadata.sectionId)

val commercialBundleUrl = JsString(
Configuration.commercial.overrideCommercialBundleUrl
.getOrElse(assetURL("javascripts/commercial/graun.standalone.commercial.js")),
)
val commercialBundleUrl =
if (ActiveExperiments.isParticipating(CommercialBundleUpdater)(request))
Configuration.commercial.overrideCommercialBundleUrl
.getOrElse(CommercialBundle.bundleUrl)
else
Configuration.commercial.overrideCommercialBundleUrl
.getOrElse(assetURL("javascripts/commercial/graun.standalone.commercial.js"))

javascriptConfig ++ config ++ commercialMetaData ++ journalismMetaData ++ Map(
("edition", JsString(edition.id)),
Expand All @@ -95,7 +100,7 @@ object JavaScriptPage {
("brazeApiKey", JsString(Configuration.braze.apiKey)),
("ipsosTag", JsString(ipsos)),
("isAdFree", JsBoolean(isAdFree(request))),
("commercialBundleUrl", commercialBundleUrl),
("commercialBundleUrl", JsString(commercialBundleUrl)),
("stage", JsString(Configuration.environment.stage)),
)
}.toMap
Expand Down

0 comments on commit 2a8e447

Please sign in to comment.