flagsmith-nodejs
Version:
Flagsmith lets you manage features flags and remote config across web, mobile and server side applications. Deliver true Continuous Integration. Get builds out faster. Control who has access to new features.
37 lines (32 loc) • 1.06 kB
text/typescript
import Flagsmith from './index.js';
import { Logger } from 'pino';
export class EnvironmentDataPollingManager {
private interval?: NodeJS.Timeout;
private main: Flagsmith;
private refreshIntervalSeconds: number;
private logger: Logger;
constructor(main: Flagsmith, refreshIntervalSeconds: number, logger: Logger) {
this.main = main;
this.refreshIntervalSeconds = refreshIntervalSeconds;
this.logger = logger;
}
start() {
const updateEnvironment = () => {
if (this.interval) clearInterval(this.interval);
this.interval = setInterval(async () => {
try {
await this.main.updateEnvironment();
} catch (error) {
this.logger.error(error, 'failed to poll environment');
}
}, this.refreshIntervalSeconds * 1000);
};
updateEnvironment();
}
stop() {
if (!this.interval) {
return;
}
clearInterval(this.interval);
}
}