-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FFM-8886 Add retries to polling and streaming for fetching flags/segm…
…ents. Add configurable axios timeout
- Loading branch information
1 parent
cec86bb
commit ba5f512
Showing
8 changed files
with
289 additions
and
33 deletions.
There are no files selected for viewing
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,48 @@ | ||
const { Client } = require("@harnessio/ff-nodejs-server-sdk"); | ||
|
||
let client = null; | ||
|
||
async function initialize(enableStream) { | ||
const apiKey = "96088ba9-cf76-40df-b1f6-63481454944f"; | ||
client = new Client(apiKey, { enableStream: enableStream, pollInterval: 2 * 60 * 1000 }); | ||
await client.waitForInitialization(); | ||
} | ||
|
||
async function getFeatureFlagValue(enableStream, { flagName, defaultValue, targetIdentifier, type = "boolean" }) { | ||
try { | ||
if (!client) await initialize(enableStream); | ||
|
||
const target = { identifier: targetIdentifier }; | ||
|
||
switch (type) { | ||
case "string": | ||
return client.stringVariation(flagName, target, getDefaultValue({ defaultValue, type })); | ||
case "number": | ||
return client.numberVariation(flagName, target, getDefaultValue({ defaultValue, type })); | ||
case "json": | ||
return client.jsonVariation(flagName, target, getDefaultValue({ defaultValue, type })); | ||
default: | ||
return client.boolVariation(flagName, target, getDefaultValue({ defaultValue, type })); | ||
} | ||
} catch (error) { | ||
console.error("Error getting feature flag value", error); | ||
return getDefaultValue({ defaultValue, type }); | ||
} | ||
} | ||
|
||
function getDefaultValue({ defaultValue, type, useLocalDefault = false }) { | ||
if (defaultValue !== undefined) return defaultValue; | ||
|
||
switch (type) { | ||
case "string": | ||
return ""; | ||
case "number": | ||
return 0; | ||
case "json": | ||
return {}; | ||
default: | ||
return useLocalDefault; | ||
} | ||
} | ||
|
||
module.exports = { getFeatureFlagValue }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,8 @@ | ||
{ | ||
"name": "getting_started", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"dependencies": { | ||
"@harnessio/ff-nodejs-server-sdk": "1.3.1" | ||
} | ||
} |
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
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
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