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

feat(splitio-api-binding): add function to poll for split changes #5

Merged
merged 8 commits into from
Dec 13, 2019

Conversation

celiawaggoner
Copy link
Contributor

No description provided.

lib/splitio-api-binding.js Outdated Show resolved Hide resolved
const allChanges = [results]
// The till value represents the timestamp of the last change included in the response.
let till = results.till
while (since !== till) {
Copy link
Contributor

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.

Copy link
Contributor Author

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:

Ideally you would keep fetching changes until this condition is fulfilled, instead of just assuming one request will get you everything. 
After this condition is true, you periodically poll for updates.
There will only be updates to the data if this condition is NOT true on a given response.

Copy link
Contributor

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?

allChanges.forEach(change => {
splitChanges.push(change.splits)
})
return { splitChanges, since }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this function returns since, will we use it somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 -1 for now

@celiawaggoner
Copy link
Contributor Author

closing for now, need to make a couple changes

const allChanges = [results]
// The till value represents the timestamp of the last change included in the response.
let till = results.till
while (since !== till) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, so much nice

const allChanges = [results]
// The till value represents the timestamp of the last change included in the response.
let till = results.till
while (since !== till) {
Copy link
Contributor

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?

@celiawaggoner celiawaggoner reopened this Dec 12, 2019
Copy link
Contributor

@rohanmurthy rohanmurthy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎆

@celiawaggoner celiawaggoner merged commit 5317c19 into master Dec 13, 2019
@celiawaggoner celiawaggoner deleted the splitchanges branch December 13, 2019 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants