Skip to content

Commit

Permalink
Merge pull request #34 from statsig-io/582sync
Browse files Browse the repository at this point in the history
Patch sync interval reset
  • Loading branch information
tore-statsig authored Aug 28, 2023
2 parents 7dfb8e0 + 37512af commit 8ef6c16
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "statsig-node",
"version": "5.8.2",
"version": "5.8.3",
"description": "Statsig Node.js SDK for usage in multi-user server environments.",
"main": "dist/index.js",
"scripts": {
Expand Down Expand Up @@ -55,4 +55,4 @@
"parser": "typescript"
}
}
}
}
4 changes: 2 additions & 2 deletions src/SpecStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,12 @@ export default class SpecStore {
let message = '';
if (syncTimerInactive) {
this.clearSyncTimer();
this._syncValues();
message = message.concat(`Force reset sync timer. Last update time: ${
this.syncTimerLastActiveTime
}, now: ${Date.now()}`);
}
if (idListsSyncTimerInactive) {
this.clearIdListsSyncTimer();
this._syncIdLists();
message = message.concat(`Force reset id list sync timer. Last update time: ${
this.idListsSyncTimerLastActiveTime
}, now: ${Date.now()}`);
Expand Down Expand Up @@ -299,13 +297,15 @@ export default class SpecStore {

private pollForUpdates() {
if (this.syncTimer == null) {
this.syncTimerLastActiveTime = Date.now();
this.syncTimer = poll(async () => {
this.syncTimerLastActiveTime = Date.now();
await this._syncValues();
}, this.syncInterval);
}

if (this.idListsSyncTimer == null) {
this.idListsSyncTimerLastActiveTime = Date.now();
this.idListsSyncTimer = poll(async () => {
this.idListsSyncTimerLastActiveTime = Date.now();
await this._syncIdLists();
Expand Down
12 changes: 12 additions & 0 deletions src/__tests__/ResetSync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ describe('Verify sync intervals reset', () => {
{ userID: '123', email: '[email protected]' },
'nfl_gate',
);
gate = await statsig.checkGate(
{ userID: '123', email: '[email protected]' },
'nfl_gate',
);
gate = await statsig.checkGate(
{ userID: '123', email: '[email protected]' },
'nfl_gate',
);
gate = await statsig.checkGate(
{ userID: '123', email: '[email protected]' },
'nfl_gate',
);
expect(gate).toBe(true);
expect(spy).toHaveBeenCalledTimes(1);
});
Expand Down
2 changes: 1 addition & 1 deletion src/utils/StatsigFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default class StatsigFetcher {
if (counter != null && counter >= 1000) {
return Promise.reject(
new StatsigTooManyRequestsError(
'Request failed because you are making the same request too frequently.',
`Request to ${url} failed because you are making the same request too frequently (${counter}).`,
),
);
}
Expand Down

0 comments on commit 8ef6c16

Please sign in to comment.