Skip to content

Commit

Permalink
api: Restore the accidentally removed concurrency limits
Browse files Browse the repository at this point in the history
Change-type: patch
  • Loading branch information
thgreasi committed Nov 9, 2023
1 parent db962ac commit d216cb8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 55 deletions.
108 changes: 53 additions & 55 deletions lib/release/api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pMap = require('p-map');
import { PinejsClientRequest } from 'pinejs-client-request';
import * as models from './models';
import { Dict } from './types';
Expand Down Expand Up @@ -133,36 +134,35 @@ export async function create(req: Request): Promise<Response> {
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;
Expand Down Expand Up @@ -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,
},
);
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d216cb8

Please sign in to comment.