Skip to content

Commit

Permalink
Increase polling frequency (#30)
Browse files Browse the repository at this point in the history
* reduce polling interval to 30 seconds. remove jitter

* make target for running tests

* remove jitter arg from poller init in spec
  • Loading branch information
petzel authored May 18, 2023
1 parent 14d0a3e commit a5ea8d4
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ test-data:
gsutil cp gs://sdk-test-data/rac-experiments-v2.json $(testDataDir)
gsutil cp -r gs://sdk-test-data/assignment-v2 $(testDataDir)

## test
.PHONY: test
test: test
yarn test:unit

## prepare
.PHONY: prepare
prepare: test-data
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eppo/node-server-sdk",
"version": "1.3.1",
"version": "1.3.2",
"description": "Eppo node server SDK",
"main": "dist/index.js",
"files": [
Expand Down
4 changes: 1 addition & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const SECOND_MILLIS = 1000;
const MINUTE_MILLIS = 60 * SECOND_MILLIS;

export const POLL_INTERVAL_MILLIS = 5 * MINUTE_MILLIS;
export const JITTER_MILLIS = 30 * SECOND_MILLIS;
export const POLL_INTERVAL_MILLIS = 30 * SECOND_MILLIS;
export const MAX_CACHE_ENTRIES = 1000;
export const REQUEST_TIMEOUT_MILLIS = 5 * SECOND_MILLIS;

Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { InMemoryConfigurationStore } from './configuration-store';
import {
BASE_URL,
MAX_CACHE_ENTRIES,
JITTER_MILLIS,
POLL_INTERVAL_MILLIS,
REQUEST_TIMEOUT_MILLIS,
} from './constants';
Expand Down Expand Up @@ -76,7 +75,6 @@ export async function init(config: IClientConfig): Promise<IEppoClient> {
}
poller = initPoller(
POLL_INTERVAL_MILLIS,
JITTER_MILLIS,
configurationRequestor.fetchAndStoreConfigurations.bind(configurationRequestor),
);
clientInstance = new EppoClient(configurationRequestor, poller, config.assignmentLogger);
Expand Down
4 changes: 2 additions & 2 deletions src/poller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ describe('initPoller', () => {
});

it('starts polling at interval', async () => {
const poller = initPoller(testInterval, 0, callback);
const poller = initPoller(testInterval, callback);
await poller.start();
td.verify(callback(), { times: 1 });
await verifyPoll(2);
await verifyPoll(3);
});

it('stops polling', async () => {
const poller = initPoller(testInterval, 0, callback);
const poller = initPoller(testInterval, callback);
await poller.start();
poller.stop();
jest.advanceTimersByTime(testInterval * 10);
Expand Down
4 changes: 1 addition & 3 deletions src/poller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export interface IPoller {

export default function initPoller(
interval: number,
jitterMillis: number,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
callback: () => Promise<any>,
): IPoller {
Expand All @@ -26,8 +25,7 @@ export default function initPoller(
}
console.error(`Error polling configurations: ${error.message}`);
}
const intervalWithJitter = interval - Math.random() * jitterMillis;
setTimeout(poll, intervalWithJitter);
setTimeout(poll, interval);
}

return {
Expand Down

0 comments on commit a5ea8d4

Please sign in to comment.