-
Notifications
You must be signed in to change notification settings - Fork 556
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commercial bundle updater 0% test (#27578)
- Loading branch information
Showing
4 changed files
with
56 additions
and
96 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters