Set timeout on migration task
MODIFY
src/migration/MigrationHandler.ts
src/migration/MigrationHandler.ts
@@ -48,7 +48,7 @@ export default class MigrationHandler {
tenantID: Constants.DEFAULT_TENANT,
action: ServerAction.MIGRATION,
module: MODULE_NAME, method: 'migrate',
- message: 'Running migration tasks...'
+ message: `Running ${processAsyncTasksOnly ? 'asynchronous' : 'synchronous'} migration tasks...`
});
// Create tasks
currentMigrationTasks.push(new SiteUsersHashIDsTask());

MODIFY
src/migration/tasks/UpdateChargingStationTemplatesTask.ts
src/migration/tasks/UpdateChargingStationTemplatesTask.ts
@@ -4,6 +4,7 @@ import Logging from '../../utils/Logging';
import MigrationTask from '../MigrationTask';
import OCPPUtils from '../../server/ocpp/utils/OCPPUtils';
import { ServerAction } from '../../types/Server';
+import { TemplateUpdateResult } from '../../types/ChargingStation';
import Tenant from '../../types/Tenant';
import TenantStorage from '../../storage/mongodb/TenantStorage';
import Utils from '../../utils/Utils';
@@ -35,7 +36,7 @@ export default class UpdateChargingStationTemplatesTask extends MigrationTask {
}
getVersion() {
- return '1.8';
+ return '1.8124';
}
private async applyTemplateToChargingStations(tenant: Tenant) {
@@ -46,8 +47,11 @@ export default class UpdateChargingStationTemplatesTask extends MigrationTask {
}, Constants.DB_PARAMS_MAX_LIMIT);
// Update
for (const chargingStation of chargingStations.result) {
+ try {
+ const chargingStationTemplateUpdated = await Utils.promiseWithTimeout<TemplateUpdateResult>(
+ 3 * 60 * 1000, OCPPUtils.enrichChargingStationWithTemplate(tenant.id, chargingStation),
+ `Time out error with ${chargingStation.id}`);
// Enrich
- const chargingStationTemplateUpdated = await OCPPUtils.enrichChargingStationWithTemplate(tenant.id, chargingStation);
let chargingStationUpdated = false;
// Check Connectors
for (const connector of chargingStation.connectors) {
@@ -67,12 +71,22 @@ export default class UpdateChargingStationTemplatesTask extends MigrationTask {
await OCPPUtils.requestAndSaveChargingStationOcppParameters(
tenant.id, chargingStation, chargingStationTemplateUpdated.ocppUpdated);
}
+ } catch (error) {
+ Logging.logError({
+ tenantID: Constants.DEFAULT_TENANT,
+ action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE,
+ source: chargingStation.id,
+ module: MODULE_NAME, method: 'applyTemplateToChargingStations',
+ message: `Charging Stations template update errors in Tenant '${tenant.name}'`,
+ detailedMessages: { error: error.message, stack: error.stack }
+ });
+ }
}
if (updated > 0) {
Logging.logDebug({
tenantID: Constants.DEFAULT_TENANT,
action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE,
- module: MODULE_NAME, method: 'updateChargingStationsWithTemplate',
+ module: MODULE_NAME, method: 'applyTemplateToChargingStations',
message: `${updated} Charging Stations have been updated with Template in Tenant '${tenant.name}'`
});
}

MODIFY
src/migration/tasks/UpdateLimitsInConsumptionsTask.ts
src/migration/tasks/UpdateLimitsInConsumptionsTask.ts
@@ -41,10 +41,6 @@ export default class UpdateLimitsInConsumptionsTask extends MigrationTask {
if (limitAmps) {
limitWatts = Utils.convertAmpToWatt(chargingStation, connector.connectorId, limitAmps);
// Update
- console.log('====================================');
- console.log(chargingStation.id);
- console.log(connector.connectorId);
- console.log({ limitWatts, limitAmps });
result = await global.database.getCollection(tenant.id, 'consumptions').updateMany(
{
chargeBoxID: chargingStation.id,
@@ -58,8 +54,6 @@ export default class UpdateLimitsInConsumptionsTask extends MigrationTask {
}
}
);
- console.log({ updated: result.modifiedCount });
- console.log('====================================');
updated += result.modifiedCount;
}
}

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -68,6 +68,20 @@ export default class Utils {
return intervalMins;
}
+ public static async promiseWithTimeout <T>(timeoutMs: number, promise: Promise<T>, failureMessage: string) {
+ let timeoutHandle: number;
+ const timeoutPromise = new Promise<never>((resolve, reject) => {
+ timeoutHandle = setTimeout(() => reject(new Error(failureMessage)), timeoutMs);
+ });
+ return Promise.race([
+ promise,
+ timeoutPromise,
+ ]).then((result) => {
+ clearTimeout(timeoutHandle);
+ return result;
+ });
+ }
+
public static logActionsResponse(
tenantID: string, action: ServerAction, module: string, method: string, actionsResponse: ActionsResponse,
messageSuccess: string, messageError: string, messageSuccessAndError: string,

Set timeout on migration task