unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
41 lines • 1.98 kB
JavaScript
import { calculateProjectHealth, calculateProjectHealthRating, } from '../domain/project-health/project-health.js';
import { batchExecute } from '../util/index.js';
import metricsHelper from '../util/metrics-helper.js';
import { FUNCTION_TIME } from '../metric-events.js';
export default class ProjectHealthService {
constructor({ projectStore, featureTypeStore, featureToggleStore, }, { getLogger, eventBus }, projectService) {
this.logger = getLogger('services/project-health-service.ts');
this.projectStore = projectStore;
this.featureTypeStore = featureTypeStore;
this.featureToggleStore = featureToggleStore;
this.projectService = projectService;
this.calculateHealthRating = calculateProjectHealthRating(this.featureTypeStore, this.featureToggleStore);
this.timer = (functionName) => metricsHelper.wrapTimer(eventBus, FUNCTION_TIME, {
className: 'ProjectHealthService',
functionName,
});
}
async getProjectHealthReport(projectId) {
const featureTypes = await this.featureTypeStore.getAll();
const overview = await this.projectService.getProjectHealth(projectId, false, undefined);
const healthRating = calculateProjectHealth(overview.features, featureTypes);
return {
...overview,
...healthRating,
};
}
async setHealthRating(batchSize = 1) {
const projects = await this.projectStore.getAll();
void batchExecute(projects, batchSize, 5000, (project) => this.setProjectHealthRating(project.id));
}
async setProjectHealthRating(projectId) {
const stopTimer = this.timer('setProjectHealthRating');
const newHealth = await this.calculateHealthRating({ id: projectId });
await this.projectStore.updateHealth({
id: projectId,
health: newHealth,
});
stopTimer();
}
}
//# sourceMappingURL=project-health-service.js.map