Skip to content

Commit

Permalink
Revert "* fix: changed name of WTP_LS_ALLOW_REGEX to WTP_LS_ALLOWED_L…
Browse files Browse the repository at this point in the history
…OCATIONS_REGEX and introduced a new option WTP_LS_ENABLED (#101)"

This reverts commit cf52ab2.
  • Loading branch information
lukaszczerpak-cloudinary committed Dec 10, 2024
1 parent cf52ab2 commit 5ac5674
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
3 changes: 1 addition & 2 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ const conf = {
},
timeout: process.env.WTP_TIMEOUT || 30000,
"locationSelector": {
"enabled": process.env.WTP_LS_ENABLED || false,
"allowedLocationsRegex": process.env.WTP_LS_ALLOWED_LOCATIONS_REGEX || '_US_',
"allowRegex": process.env.WTP_LS_ALLOW_REGEX || '_US_',
"cacheTtl": process.env.WTP_LS_CACHE_TTL || 10,
"updateTimeout": process.env.WTP_LS_UPDATE_TIMEOUT || 20,
"defaultLocation": process.env.WTP_LS_DEFAULT_LOCATION || "IAD_US_01"
Expand Down
7 changes: 3 additions & 4 deletions wtp/locationSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ const locationMetrics = {
class LocationSelector {
constructor() {
if (!LocationSelector.instance) {
this.enabled = config.get('wtp.locationSelector.enabled');
this.cachedAllLocations = [];
this.location = config.get('wtp.locationSelector.defaultLocation');
this.allowedLocationsRegex = new RegExp(config.get('wtp.locationSelector.allowedLocationsRegex'));
this.allowRegex = new RegExp(config.get('wtp.locationSelector.allowRegex'));
this.lastUpdated = null;
this.mutex = withTimeout(new Mutex(), config.get('wtp.locationSelector.updateTimeout') * 1000);
LocationSelector.instance = this;
Expand Down Expand Up @@ -115,7 +114,7 @@ class LocationSelector {
}

const filtered = Object.keys(newLocations)
.filter(key => this.allowedLocationsRegex.test(key))
.filter(key => this.allowRegex.test(key))
.reduce((arr, key) => {
return [...arr, newLocations[key]];
}, []);
Expand Down Expand Up @@ -155,7 +154,7 @@ class LocationSelector {
};

async getLocation() {
if (this.enabled && this.isExpired()) {
if (this.isExpired()) {
try {
await this.mutex.runExclusive(async () => {
if (this.isExpired()) {
Expand Down

0 comments on commit 5ac5674

Please sign in to comment.