-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JS SDK support for timeouts and retries on startup (#22)
- Loading branch information
1 parent
730bab1
commit 4a35df5
Showing
101 changed files
with
1,627 additions
and
630 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 |
---|---|---|
@@ -1,3 +1,43 @@ | ||
## 6.0.0 (June 24, 2016) | ||
|
||
* In the browser land we allow quick retries before start using the refresh | ||
rates defined for segments and splits, plus the possibility of receive an | ||
event when the SDK is taking to much time to startup. | ||
|
||
```html | ||
<script src="//cdn.split.io/sdk/split-6.0.0.min.js"></script> | ||
<script> | ||
var sdk = splitio({ | ||
core: { | ||
authorizationKey: '<your-token>', | ||
key: '[email protected]' | ||
}, | ||
startup: { | ||
// timeout an *initial* request after 0.8 seconds (only affects startup) | ||
requestTimeoutBeforeReady: 0.8, | ||
// how many quick retries are allowed before use the schedulers refresh | ||
// rates (only affects startup) | ||
retriesOnFailureBeforeReady: 1, | ||
// maximum amount of seconds we are going to wait for the ready event | ||
readyTimeout: 1.5 | ||
} | ||
}); | ||
|
||
sdk.on(sdk.Event.SDK_READY_TIMED_OUT, function () { | ||
// this callback will be called after 1.5 seconds if and only if the SDK | ||
// is not ready for that time | ||
}); | ||
|
||
sdk.on(sdk.Event.SDK_READY, function () { | ||
// the SDK is ready for start making evaluations with your data | ||
}); | ||
|
||
sdk.on(sdk.Event.SDK_UPDATE, function () { | ||
// fired each time the SDK state change | ||
}); | ||
</script> | ||
``` | ||
|
||
## 5.1.1 (June 13, 2016) | ||
|
||
* None API changes. Bug fixing release. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["es2015-node4"] | ||
} |
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 @@ | ||
/lib |
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,28 @@ | ||
# Crazy CDN | ||
|
||
The concept is a proxy which add delays and eventually errors in the services | ||
using express middlewares. | ||
|
||
## How to run | ||
|
||
1. `nvm install v4` | ||
2. `nvm use v4` | ||
3. `npm install` | ||
4. `npm run b` | ||
5. `npm start` | ||
6. `The proxy server is running in localhost:3000` | ||
|
||
By default the target is hardcoded to be staging servers, but you could change | ||
that quickly. | ||
|
||
> HTTPS is disabled using a "un-secure" scheme because we are a man in the | ||
middle. | ||
|
||
## How to development | ||
|
||
1. `nvm install v4` | ||
2. `nvm use v4` | ||
3. `npm install` | ||
4. `npm run w` => live recompilation on changes | ||
5. `npm run m` => live nodejs reload after recompilation changes | ||
6. `The proxy server is running in localhost:3000` |
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,30 @@ | ||
{ | ||
"name": "@splitsoftware/crazy-cdn", | ||
"version": "1.0.0", | ||
"description": "Crazy CDN", | ||
"readme": "README.md", | ||
"author": "Facundo Cabrera <[email protected]>", | ||
"homepage": "https://github.com/splitio/javascript-client", | ||
"license": "Apache-2.0", | ||
"repository": "https://github.com/splitio/javascript-client/tree/master/crazy-cdn", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"start": "node lib/index.js", | ||
"m": "nodemon lib/index.js", | ||
"b": "babel src --out-dir lib", | ||
"w": "babel src --out-dir lib -w" | ||
}, | ||
"engines": { | ||
"node": "4.4.3", | ||
"npm": "3.9.3" | ||
}, | ||
"dependencies": { | ||
"express": "^4.14.0", | ||
"http-proxy": "^1.14.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.10.1", | ||
"babel-preset-es2015-node4": "^2.1.0", | ||
"nodemon": "^1.9.2" | ||
} | ||
} |
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,38 @@ | ||
const express = require('express'); | ||
const app = express(); | ||
|
||
const httpProxy = require('http-proxy'); | ||
const proxy = httpProxy.createProxyServer({}); | ||
|
||
app.use(function(err, req, res, next) { | ||
res.status(503).send(JSON.stringigy(err)); | ||
}); | ||
|
||
app.use(function delay(req, res, next) { | ||
setTimeout(next, Math.random() * 3000); | ||
}); | ||
|
||
app.use(function internalError(req, res, next) { | ||
// if (Math.random() > 0.8) { | ||
if (false) { | ||
res.status(500).send({ | ||
status: 500, | ||
message: 'internal error', | ||
type:'internal' | ||
}); | ||
} else { | ||
next(); | ||
} | ||
}); | ||
|
||
app.all('/*', function(req, res) { | ||
proxy.web(req, res, { | ||
target: 'https://sdk-aws-staging.split.io', | ||
secure: false, | ||
changeOrigin: true | ||
}); | ||
}); | ||
|
||
app.listen(3000, function () { | ||
console.log('Crazy proxy at 3000 port'); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,51 @@ | ||
'use strict'; | ||
|
||
console.log('SPLIT DEMO!'); | ||
|
||
// | ||
// Bellow you will see how you could define features and the defaults treatments | ||
// for each one. | ||
// | ||
// NOTICE: there is NONE asyncronous initialization in offline mode, because you | ||
// are providing the default feedback of the engine. | ||
// | ||
|
||
var sdk = splitio({ | ||
core: { | ||
authorizationKey: '29lsbc79peklpksdto0a90s2e3u1agv8vqm2', // change this with your api token | ||
key: '4a2c4490-ced1-11e5-9b97-d8a25e8b1578' // change this with your user key | ||
}/*, | ||
// change this with your api token | ||
authorizationKey: '5p2c0r4so20ill66lm35i45h6pkvrd2skmib', | ||
// change this with your user key | ||
key: '1f84e5ddb06a3e66145ccfc1aac247' | ||
}, | ||
scheduler: { | ||
featuresRefreshRate: 1, // fetch feature updates each 1 sec | ||
segmentsRefreshRate: 1, // fetch segment updates each 1 sec | ||
metricsRefreshRate: 30, // publish metrics each 30 sec | ||
impressionsRefreshRate: 30 // publish evaluations each 30 sec | ||
}*/ | ||
// fetch feature updates each 15 sec | ||
featuresRefreshRate: 15, | ||
// fetch segment updates each 15 sec | ||
segmentsRefreshRate: 15, | ||
// publish metrics each 15 sec | ||
metricsRefreshRate: 15, | ||
// publish evaluations each 15 sec | ||
impressionsRefreshRate: 15 | ||
}, | ||
urls: { | ||
sdk: 'https://sdk-aws-staging.split.io/api', | ||
events: 'https://events-aws-staging.split.io/api' | ||
} | ||
}); | ||
|
||
console.info( sdk.getTreatment('early_evaluation') , '<= We are asking for a feature before the engine is ready'); | ||
console.assert( | ||
sdk.getTreatment('in_five_keys') === 'control' | ||
); | ||
|
||
sdk.on(sdk.Event.SDK_READY_TIMED_OUT, function onTimeout() { | ||
console.log('SDK ready timeout'); | ||
}); | ||
|
||
sdk.ready().then(function () { | ||
console.info( sdk.getTreatment('js_sdk'), '<= This answer depends on split configurations' ); | ||
sdk.on(sdk.Event.SDK_READY, function onSDKReady() { | ||
console.assert(sdk.getTreatment('in_five_keys') === 'activated'); | ||
}); | ||
|
||
sdk.on(sdk.Event.SDK_UPDATE, function onSDKUpdate() { | ||
console.log(sdk.getTreatment('in_five_keys')); | ||
console.log(sdk.getTreatment('in_ten_keys')); | ||
}); | ||
|
||
// just to show up the deprecated message | ||
sdk.ready().then(function () {}); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@splitsoftware/splitio-browser", | ||
"version": "5.1.1", | ||
"version": "6.0.0", | ||
"description": "Split SDK tools for the browser", | ||
"author": "Facundo Cabrera <[email protected]>", | ||
"homepage": "https://github.com/splitio/javascript-client", | ||
|
@@ -25,7 +25,7 @@ | |
"sdk" | ||
], | ||
"dependencies": { | ||
"@splitsoftware/splitio": "5.1.1", | ||
"@splitsoftware/splitio": "6.0.0", | ||
"browserify": "^13.0.0", | ||
"browserify-derequire": "^0.9.4", | ||
"bundle-collapser": "^1.2.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
Oops, something went wrong.