Skip to content

Commit 15520ae

Browse files
committed
IOT-1157: Avoid too many concurrent connections to chirpstack
1 parent f09e983 commit 15520ae

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"ajv": "^6.12.6",
4242
"axios-cache-adapter": "^2.5.0",
4343
"bcryptjs": "^2.4.3",
44+
"bluebird": "^3.7.2",
4445
"class-transformer": "^0.3.1",
4546
"class-validator": "^0.12.2",
4647
"compression": "^1.7.4",
@@ -67,6 +68,7 @@
6768
"devDependencies": {
6869
"@nestjs/cli": "^7.5.4",
6970
"@nestjs/testing": "^7.6.1",
71+
"@types/bluebird": "^3.5.33",
7072
"@types/compression": "^1.7.0",
7173
"@types/cookie-parser": "^1.4.2",
7274
"@types/cron": "^1.7.2",

src/services/chirpstack/chirpstack-gateway.service.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
NotFoundException,
88
} from "@nestjs/common";
99
import { AxiosResponse } from "axios";
10-
10+
import * as BluebirdPromise from "bluebird";
1111
import { ChirpstackErrorResponseDto } from "@dto/chirpstack/chirpstack-error-response.dto";
1212
import { ChirpstackResponseStatus } from "@dto/chirpstack/chirpstack-response.dto";
1313
import { CreateGatewayDto } from "@dto/chirpstack/create-gateway.dto";
@@ -113,19 +113,25 @@ export class ChirpstackGatewayService extends GenericChirpstackConfigurationServ
113113
}
114114

115115
private async enrichWithOrganizationId(results: GatewayResponseDto[]) {
116-
await Promise.all(
117-
results.map(async x => {
118-
try {
119-
const gw = await this.getOne(x.id);
120-
x.internalOrganizationId = gw.gateway.internalOrganizationId;
121-
} catch (err) {
122-
this.logger.error(
123-
`Failed to fetch gateway details for id ${x.id}`,
124-
err
125-
);
126-
x.internalOrganizationId = null;
116+
await BluebirdPromise.all(
117+
BluebirdPromise.map(
118+
results,
119+
async x => {
120+
try {
121+
const gw = await this.getOne(x.id);
122+
x.internalOrganizationId = gw.gateway.internalOrganizationId;
123+
} catch (err) {
124+
this.logger.error(
125+
`Failed to fetch gateway details for id ${x.id}`,
126+
err
127+
);
128+
x.internalOrganizationId = null;
129+
}
130+
},
131+
{
132+
concurrency: 50,
127133
}
128-
})
134+
)
129135
);
130136
}
131137

0 commit comments

Comments
 (0)