From 63084336b22c46215ef0c07b7c8183dc6838124a Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Wed, 8 Nov 2023 19:12:53 +0200 Subject: [PATCH] api: Restore the accidentally removed concurrency limits Change-type: patch --- lib/release/api.ts | 108 ++++++++++++++++++++++----------------------- package.json | 1 + 2 files changed, 54 insertions(+), 55 deletions(-) diff --git a/lib/release/api.ts b/lib/release/api.ts index 05bf054..3928e94 100644 --- a/lib/release/api.ts +++ b/lib/release/api.ts @@ -1,3 +1,4 @@ +import pMap = require('p-map'); import { PinejsClientRequest } from 'pinejs-client-request'; import * as models from './models'; import { Dict } from './types'; @@ -133,36 +134,35 @@ export async function create(req: Request): Promise { const res = { release, serviceImages: {} } as Response; // Create services and associated image, labels and env vars - await Promise.all( - Object.entries(req.composition.services).map( - async ([serviceName, serviceDescription]) => { - const service = await getOrCreateService(api, { - application: application.id, - service_name: serviceName, - }); + await pMap( + Object.entries(req.composition.services), + async ([serviceName, serviceDescription]) => { + const service = await getOrCreateService(api, { + application: application.id, + service_name: serviceName, + }); + + // Create images and attach labels and env vars + const img = await createImage( + api, + res.release.id, + serviceDescription.labels, + serviceDescription.environment, + { + is_a_build_of__service: service.id, + status: 'running', + start_timestamp: new Date(), + }, + ); - // Create images and attach labels and env vars - const img = await createImage( - api, - res.release.id, - serviceDescription.labels, - serviceDescription.environment, - { - is_a_build_of__service: service.id, - status: 'running', - start_timestamp: new Date(), - }, - ); - - // Amend response with image details for the service - res.serviceImages[serviceName] = img; - - return service; - }, - { - concurrency: MAX_CONCURRENT_REQUESTS, - }, - ), + // Amend response with image details for the service + res.serviceImages[serviceName] = img; + + return service; + }, + { + concurrency: MAX_CONCURRENT_REQUESTS, + }, ); return res; @@ -239,36 +239,34 @@ async function createImage( }); if (labels) { - await Promise.all( - Object.entries(labels).map( - ([name, value]) => { - return models.create(api, 'image_label', { - release_image: releaseImage.id, - label_name: name, - value: (value || '').toString(), - }); - }, - { - concurrency: MAX_CONCURRENT_REQUESTS, - }, - ), + await pMap( + Object.entries(labels), + ([name, value]) => { + return models.create(api, 'image_label', { + release_image: releaseImage.id, + label_name: name, + value: (value || '').toString(), + }); + }, + { + concurrency: MAX_CONCURRENT_REQUESTS, + }, ); } if (envvars) { - await Promise.all( - Object.entries(envvars).map( - ([name, value]) => { - return models.create(api, 'image_environment_variable', { - release_image: releaseImage.id, - name, - value: (value || '').toString(), - }); - }, - { - concurrency: MAX_CONCURRENT_REQUESTS, - }, - ), + await pMap( + Object.entries(envvars), + ([name, value]) => { + return models.create(api, 'image_environment_variable', { + release_image: releaseImage.id, + name, + value: (value || '').toString(), + }); + }, + { + concurrency: MAX_CONCURRENT_REQUESTS, + }, ); } diff --git a/package.json b/package.json index 236bdf6..7e3abad 100644 --- a/package.json +++ b/package.json @@ -84,6 +84,7 @@ "klaw": "^4.0.1", "lodash": "^4.17.19", "mz": "^2.7.0", + "p-map": "^4.0.0", "pinejs-client-request": "^7.3.5", "request": "^2.88.2", "semver": "^7.3.5",