-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat(splitio-api-binding): add function to poll for split changes #5
Changes from 5 commits
75661b8
3f7f557
cea35a7
847f5c9
3d38a58
5c5cdd3
093d6bb
8a12977
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ const https = require('https') | |
const axios = require('axios') | ||
|
||
const SPLITIO_API_URI = 'https://sdk.split.io/api' | ||
const SINCE_VALUE_FOR_FIRST_REQUEST = -1 | ||
|
||
const httpsAgent = new https.Agent({ | ||
keepAlive: true, | ||
|
@@ -53,11 +54,40 @@ class SplitioApiBinding { | |
} | ||
} | ||
|
||
/** | ||
* Polls the Split.io API until since and till timestamps are the same. | ||
*/ | ||
async getAllChanges ({ path }) { | ||
let since = SINCE_VALUE_FOR_FIRST_REQUEST | ||
let results = await this.httpGet({ path, since }) | ||
const allChanges = [results] | ||
// The till value represents the timestamp of the last change included in the response. | ||
let till = results.till | ||
while (since !== till) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this work? const since = SINCE_VALUE_FOR_FIRST_REQUEST
const allChanges = []
while (true) {
const results = await this.httpGet({ path, since })
if (since === results.till) {
break
}
allChanges.push(results)
since = results.till
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah yes, so much nice |
||
since = till | ||
results = await this.httpGet({ path, since }) | ||
till = results.till | ||
if (since === till) { | ||
return { allChanges, since } | ||
} | ||
allChanges.push(results) | ||
} | ||
return { allChanges, since } | ||
} | ||
|
||
/** | ||
* Get split data. | ||
*/ | ||
getSplitChanges () { | ||
throw new Error('Not implemented') | ||
async getSplitChanges () { | ||
const path = '/splitChanges' | ||
const splitChanges = [] | ||
const { allChanges, since } = await this.getAllChanges({ path }) | ||
allChanges.forEach(change => { | ||
change.splits.forEach(split => { | ||
splitChanges.push(split) | ||
}) | ||
}) | ||
return { splitChanges, since } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder why this function returns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, the FE data loader will use it so that the SDK knows what timestamp to use for polling for updates There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. edit: talked to silas more about this -- we'll eventually keep track of this on the backend but are just going to poll with |
||
} | ||
|
||
/** | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these values guaranteed to converge? I am worried that there would be a case where this runs infinitely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think they will -- it would only run a long time if there's a huge number splits
from the doc from split:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The potentially infinite loop makes me nervous. E.g., if split.io API has a bug, that bubbles up as a infinite loop in our product code. Can we add a limit on the loop?