UNPKG

steadybit

Version:

Command-line interface to interact with the Steadybit API

95 lines 4.45 kB
"use strict"; // SPDX-License-Identifier: MIT // SPDX-FileCopyrightText: 2022 Steadybit GmbH var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.dump = dump; const promises_1 = __importDefault(require("fs/promises")); const get_1 = require("../team/get"); const api_1 = require("./api"); const files_1 = require("./files"); function dump(options) { return __awaiter(this, void 0, void 0, function* () { yield ensureDirectoryExists(options.directory); let totalExperiments = 0; let totalExecutions = 0; for (const team of yield (0, get_1.getAllTeams)(false)) { process.stdout.write(`Fetching experiments for team ${team.name} (${team.key})... `); const { countExperiments, countExecutions } = yield getAllExperimentsForTeam(team, options.directory); totalExperiments += countExperiments; totalExecutions += countExecutions; process.stdout.write(`experiments: ${countExperiments}, executions: ${countExecutions}\n`); } console.log(`Written ${totalExperiments} experiments with ${totalExecutions} executions`); }); } function removeDeprecatedFields(experiment) { if (Array.isArray(experiment.lanes)) { experiment.lanes.forEach(lane => { if (Array.isArray(lane.steps)) { lane.steps.forEach((step) => { if (step && typeof step === 'object' && 'radius' in step) { delete step.radius.query; delete step.radius.list; } }); } }); } return experiment; } function getAllExperimentsForTeam(team, dir) { return __awaiter(this, void 0, void 0, function* () { const response = yield (0, api_1.fetchExperiments)(team.key); const c = yield Promise.all(response.experiments.map((item) => __awaiter(this, void 0, void 0, function* () { const subdir = `${dir}/${item.key}`; yield ensureDirectoryExists(subdir); const experiment = yield (0, api_1.fetchExperiment)(item.key); yield (0, files_1.writeYamlFile)(`${subdir}/experiment.yaml`, removeDeprecatedFields(experiment)); return yield getAllExecutionsForExperiment(item.key, subdir); }))); return { countExperiments: response.experiments.length, countExecutions: c.reduce((a, b) => a + b, 0), }; }); } function getAllExecutionsForExperiment(key, dir) { return __awaiter(this, void 0, void 0, function* () { const response = yield (0, api_1.fetchExecutionsForExperiment)(key); yield new Promise(resolve => setTimeout(resolve, 1000)); const c = yield Promise.all(response.executions.map((item) => __awaiter(this, void 0, void 0, function* () { let count = 0; try { if (count++ % 100 == 0) { //poor man's throttling yield new Promise(resolve => setTimeout(resolve, 1000)); } const execution = yield (0, api_1.getExperimentExecution)(item.id, false); yield (0, files_1.writeYamlFile)(`${dir}/execution-${item.id}.yaml`, execution); return 1; } catch (_a) { return 0; } }))); return c.reduce((a, b) => a + b, 0); }); } function ensureDirectoryExists(dir) { return __awaiter(this, void 0, void 0, function* () { yield promises_1.default.mkdir(dir, { recursive: true }); }); } //# sourceMappingURL=dump.js.map