Pull tokens in //
MODIFY
src/client/ocpi/CpoOCPIClient.ts
src/client/ocpi/CpoOCPIClient.ts
@@ -101,7 +101,9 @@ export default class CpoOCPIClient extends OCPIClient {
}
const tags = await TagStorage.getTags(this.tenant.id,
{ tagIDs: tagIDs }, Constants.DB_PARAMS_MAX_LIMIT);
- for (const token of response.data.data as OCPIToken[]) {
+ const tokens = response.data.data as OCPIToken[];
+ if (!Utils.isEmptyArray(tokens)) {
+ await Promise.map(tokens, async (token) => {
try {
// Get eMSP user
const email = OCPIUtils.buildEmspEmailFromOCPIToken(token, this.ocpiEndpoint.countryCode, this.ocpiEndpoint.partyId);
@@ -124,6 +126,8 @@ export default class CpoOCPIClient extends OCPIClient {
`Failed to update Issuer '${token.issuer}' - Token ID '${token.uid}': ${error.message}`
);
}
+ },
+ { concurrency: Constants.OCPI_MAX_PARALLEL_REQUESTS });
}
const nextUrl = OCPIUtils.getNextUrl(response.headers.link);
if (nextUrl && nextUrl.length > 0 && nextUrl !== tokensUrl) {
@@ -669,8 +673,8 @@ export default class CpoOCPIClient extends OCPIClient {
}
// Get all locations
const locations = await OCPIUtilsService.getAllLocations(this.tenant, 0, 0, options, false);
- // Loop through locations
- for (const location of locations.result) {
+ if (!Utils.isEmptyArray(locations.result)) {
+ await Promise.map(locations.result, async (location) => {
// Get the Charging Station should be processed
let currentSkip = 0;
let evses: OCPIEvse[];
@@ -717,6 +721,8 @@ export default class CpoOCPIClient extends OCPIClient {
}
currentSkip += Constants.DB_RECORD_COUNT_DEFAULT;
} while (!Utils.isEmptyArray(evses));
+ },
+ { concurrency: Constants.OCPI_MAX_PARALLEL_REQUESTS });
}
// Save result in ocpi endpoint
this.ocpiEndpoint.lastPatchJobOn = startDate;

MODIFY
src/client/ocpi/EmspOCPIClient.ts
src/client/ocpi/EmspOCPIClient.ts
-import { OCPIToken, OCPITokenType, OCPITokenWhitelist } from '../../types/ocpi/OCPIToken';
+import { OCPIToken, OCPITokenWhitelist } from '../../types/ocpi/OCPIToken';
import BackendError from '../../exception/BackendError';
import ChargingStation from '../../types/ChargingStation';
@@ -416,45 +416,6 @@ export default class EmspOCPIClient extends OCPIClient {
}
}
- // Use by pushToken() for each Token, not scaling if thousand of them
- // private async checkToken(tokenUid: string): Promise<boolean> {
- // // Get tokens endpoint url
- // const tokensUrl = this.getEndpointUrl('tokens', ServerAction.OCPI_CHECK_TOKENS);
- // // Read configuration to retrieve
- // const countryCode = this.getLocalCountryCode(ServerAction.OCPI_CHECK_TOKENS);
- // const partyID = this.getLocalPartyID(ServerAction.OCPI_CHECK_TOKENS);
- // // Build url to IOP
- // const fullUrl = tokensUrl + `/${countryCode}/${partyID}/${tokenUid}`;
- // // Call IOP
- // const response = await this.axiosInstance.get(
- // fullUrl,
- // {
- // headers: {
- // Authorization: `Token ${this.ocpiEndpoint.token}`
- // },
- // });
- // Logging.logDebug({
- // tenantID: this.tenant.id,
- // action: ServerAction.OCPI_CHECK_LOCATIONS,
- // message: `Token ID '${tokenUid}' checked successfully`,
- // module: MODULE_NAME, method: 'checkToken',
- // detailedMessages: { response : response.data }
- // });
- // const checkedToken = response.data.data as OCPILocation;
- // if (checkedToken) {
- // return true;
- // }
- // // Check response
- // if (!response.data) {
- // throw new BackendError({
- // action: ServerAction.OCPI_CHECK_TOKENS,
- // message: `Get Token ID '${tokenUid}' failed with status ${JSON.stringify(response)}`,
- // module: MODULE_NAME, method: 'getToken',
- // detailedMessages: { response: response.data }
- // });
- // }
- // }
-
public async pushToken(token: OCPIToken): Promise<boolean> {
// Get tokens endpoint url
const tokensUrl = this.getEndpointUrl('tokens', ServerAction.OCPI_PUSH_TOKENS);

Pull tokens in //