Avoid logging start of disabled components (Scheduler and AsyncTask)
MODIFY
src/async-task/AsyncTaskManager.ts
src/async-task/AsyncTaskManager.ts
@@ -5,7 +5,6 @@ import AbstractAsyncTask from './AsyncTask';
import AsyncTaskConfiguration from '../types/configuration/AsyncTaskConfiguration';
import AsyncTaskStorage from '../storage/mongodb/AsyncTaskStorage';
import BillTransactionAsyncTask from './tasks/BillTransactionAsyncTask';
-import Configuration from '../utils/Configuration';
import Constants from '../utils/Constants';
import LockingHelper from '../locking/LockingHelper';
import LockingManager from '../locking/LockingManager';
@@ -31,13 +30,12 @@ const MODULE_NAME = 'AsyncTaskManager';
export default class AsyncTaskManager {
private static asyncTaskConfig: AsyncTaskConfiguration;
- public static async init(): Promise<void> {
- // Get the conf
- AsyncTaskManager.asyncTaskConfig = Configuration.getAsyncTaskConfig();
- if (AsyncTaskManager.asyncTaskConfig?.active) {
+ public static async init(asyncTaskConfig: AsyncTaskConfiguration): Promise<void> {
+ // Keep the conf
+ AsyncTaskManager.asyncTaskConfig = asyncTaskConfig;
// Turn all Running task to Pending
await AsyncTaskStorage.updateRunningAsyncTaskToPending();
- // Run it
+ // First run
void AsyncTaskManager.handleAsyncTasks();
// Listen to DB events
await global.database.watchDatabaseCollection(Constants.DEFAULT_TENANT_OBJECT, 'asynctasks',
@@ -53,11 +51,8 @@ export default class AsyncTaskManager {
}
);
}
- }
public static async handleAsyncTasks(): Promise<void> {
- // Active?
- if (AsyncTaskManager.asyncTaskConfig?.active) {
await Logging.logDebug({
tenantID: Constants.DEFAULT_TENANT,
action: ServerAction.ASYNC_TASK,
@@ -167,7 +162,6 @@ export default class AsyncTaskManager {
});
}
}
- }
private static async createTask(asyncTask: AsyncTask): Promise<AbstractAsyncTask> {
switch (asyncTask.name) {

MODIFY
src/scheduler/SchedulerManager.ts
src/scheduler/SchedulerManager.ts
@@ -7,7 +7,6 @@ import CheckOfflineChargingStationsTask from './tasks/CheckOfflineChargingStatio
import CheckPreparingSessionNotStartedTask from './tasks/CheckPreparingSessionNotStartedTask';
import CheckSessionNotStartedAfterAuthorizeTask from './tasks/CheckSessionNotStartedAfterAuthorizeTask';
import CheckUserAccountInactivityTask from './tasks/CheckUserAccountInactivityTask';
-import Configuration from '../utils/Configuration';
import Constants from '../utils/Constants';
import Logging from '../utils/Logging';
import LoggingDatabaseTableCleanupTask from './tasks/LoggingDatabaseTableCleanupTask';
@@ -23,6 +22,7 @@ import OCPIPushCdrsTask from './tasks/ocpi/OCPIPushCdrsTask';
import OCPIPushEVSEStatusesTask from './tasks/ocpi/OCPIPushEVSEStatusesTask';
import OICPPushEvseDataTask from './tasks/oicp/OICPPushEvseDataTask';
import OICPPushEvseStatusTask from './tasks/oicp/OICPPushEvseStatusTask';
+import SchedulerConfiguration from '../types/configuration/SchedulerConfiguration';
import SchedulerTask from './SchedulerTask';
import { ServerAction } from '../types/Server';
import SynchronizeBillingInvoicesTask from './tasks/SynchronizeBillingInvoicesTask';
@@ -35,11 +35,11 @@ import cron from 'node-cron';
const MODULE_NAME = 'SchedulerManager';
export default class SchedulerManager {
- private static schedulerConfig = Configuration.getSchedulerConfig();
+ private static schedulerConfig: SchedulerConfiguration;
- public static async init(): Promise<void> {
- // Active?
- if (SchedulerManager.schedulerConfig.active) {
+ public static async init(schedulerConfig: SchedulerConfiguration): Promise<void> {
+ // Keep the conf
+ SchedulerManager.schedulerConfig = schedulerConfig;
// Log
await Logging.logInfo({
tenantID: Constants.DEFAULT_TENANT,
@@ -168,14 +168,5 @@ export default class SchedulerManager {
});
}
}
- } else {
- // Log
- await Logging.logWarning({
- tenantID: Constants.DEFAULT_TENANT,
- action: ServerAction.SCHEDULER,
- module: MODULE_NAME, method: 'init',
- message: 'The Scheduler is inactive'
- });
- }
}
}

MODIFY
src/start.ts
src/start.ts
import CentralSystemConfiguration, { CentralSystemImplementation } from './types/configuration/CentralSystemConfiguration';
import { ServerAction, ServerType } from './types/Server';
+import AsyncTaskConfiguration from './types/configuration/AsyncTaskConfiguration';
import AsyncTaskManager from './async-task/AsyncTaskManager';
import CentralRestServer from './server/rest/CentralRestServer';
import CentralSystemRestServiceConfiguration from './types/configuration/CentralSystemRestServiceConfiguration';
@@ -21,6 +22,7 @@ import ODataServer from './server/odata/ODataServer';
import ODataServiceConfiguration from './types/configuration/ODataServiceConfiguration';
import OICPServer from './server/oicp/OICPServer';
import OICPServiceConfiguration from './types/configuration/OICPServiceConfiguration';
+import SchedulerConfiguration from './types/configuration/SchedulerConfiguration';
import SchedulerManager from './scheduler/SchedulerManager';
import SoapCentralSystemServer from './server/ocpp/soap/SoapCentralSystemServer';
import StorageConfiguration from './types/configuration/StorageConfiguration';
@@ -45,6 +47,8 @@ export default class Bootstrap {
private static oDataServer: ODataServer;
private static database: MongoDBStorage;
private static migrationConfig: MigrationConfiguration;
+ private static asyncTaskConfig: AsyncTaskConfiguration;
+ private static schedulerConfig: SchedulerConfiguration;
public static async start(): Promise<void> {
let serverStarted: ServerType[] = [];
@@ -63,6 +67,23 @@ export default class Bootstrap {
Bootstrap.oicpConfig = Configuration.getOICPServiceConfig();
Bootstrap.oDataServerConfig = Configuration.getODataServiceConfig();
Bootstrap.migrationConfig = Configuration.getMigrationConfig();
+ Bootstrap.asyncTaskConfig = Configuration.getAsyncTaskConfig();
+ Bootstrap.schedulerConfig = Configuration.getSchedulerConfig();
+
+ // -------------------------------------------------------------------------
+ // Listen to promise failure
+ // -------------------------------------------------------------------------
+ process.on('unhandledRejection', (reason: any, p: any): void => {
+ // eslint-disable-next-line no-console
+ Logging.logConsoleError(`Unhandled Rejection: ${p?.toString()}, reason: ${reason as string}`);
+ void Logging.logError({
+ tenantID: Constants.DEFAULT_TENANT,
+ action: ServerAction.UNKNOWN_ACTION,
+ module: MODULE_NAME, method: 'start',
+ message: `Unhandled Rejection: ${(reason ? (reason.message ?? reason) : 'Not provided')}`,
+ detailedMessages: (reason ? reason.stack : null)
+ });
+ });
// -------------------------------------------------------------------------
// Connect to the DB
@@ -91,18 +112,6 @@ export default class Bootstrap {
await MigrationHandler.migrate();
await this.logDuration(startTimeMillis, 'Migration has been run successfully');
}
- // Listen to promise failure
- process.on('unhandledRejection', (reason: any, p: any): void => {
- // eslint-disable-next-line no-console
- Logging.logConsoleError(`Unhandled Rejection: ${p?.toString()}, reason: ${reason as string}`);
- void Logging.logError({
- tenantID: Constants.DEFAULT_TENANT,
- action: ServerAction.UNKNOWN_ACTION,
- module: MODULE_NAME, method: 'start',
- message: `Unhandled Rejection: ${(reason ? (reason.message ?? reason) : 'Not provided')}`,
- detailedMessages: (reason ? reason.stack : null)
- });
- });
// -------------------------------------------------------------------------
// Start all the Servers
@@ -115,21 +124,25 @@ export default class Bootstrap {
// -------------------------------------------------------------------------
// Init the Scheduler
// -------------------------------------------------------------------------
+ if (Bootstrap.schedulerConfig?.active) {
startTimeMillis = await this.logAndGetStartTimeMillis('Scheduler is starting...');
// Start the Scheduler
- await SchedulerManager.init();
+ await SchedulerManager.init(Bootstrap.schedulerConfig);
await this.logDuration(startTimeMillis, 'Scheduler has been started successfully');
+ }
// -------------------------------------------------------------------------
// Init the Async Task
// -------------------------------------------------------------------------
+ if (Bootstrap.asyncTaskConfig?.active) {
startTimeMillis = await this.logAndGetStartTimeMillis('Async Task manager is starting...');
// Start the Async Manager
- await AsyncTaskManager.init();
+ await AsyncTaskManager.init(Bootstrap.asyncTaskConfig);
await this.logDuration(startTimeMillis, 'Async Task manager has been started successfully');
+ }
// Update of manually uploaded data
- if (Bootstrap.migrationConfig.active) {
+ if (Bootstrap.migrationConfig?.active) {
// -------------------------------------------------------------------------
// Update Charging Station Templates
// -------------------------------------------------------------------------

Avoid logging start of disabled components (Scheduler and AsyncTask)