Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: changed name of WTP_LS_ALLOW_REGEX to WTP_LS_ALLOWED_LOCATIONS_REGEX and introduced a new option WTP_LS_ENABLED #102

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const conf = {
},
timeout: process.env.WTP_TIMEOUT || 30000,
"locationSelector": {
"allowRegex": process.env.WTP_LS_ALLOW_REGEX || '_US_',
"enabled": process.env.WTP_LS_ENABLED === 'true',
"allowedLocationsRegex": process.env.WTP_LS_ALLOWED_LOCATIONS_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: 4 additions & 3 deletions wtp/locationSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ 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.allowRegex = new RegExp(config.get('wtp.locationSelector.allowRegex'));
this.allowedLocationsRegex = new RegExp(config.get('wtp.locationSelector.allowedLocationsRegex'));
this.lastUpdated = null;
this.mutex = withTimeout(new Mutex(), config.get('wtp.locationSelector.updateTimeout') * 1000);
LocationSelector.instance = this;
Expand Down Expand Up @@ -114,7 +115,7 @@ class LocationSelector {
}

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

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