Removed circular deps between AsyncTaskManager -> *
ADD
src/async-task/AsyncTaskBuilder.ts
+import AsyncTask, { AsyncTaskStatus } from '../types/AsyncTask';
+
+import AsyncTaskStorage from '../storage/mongodb/AsyncTaskStorage';
+import Constants from '../utils/Constants';
+import Logging from '../utils/Logging';
+import { ServerAction } from '../types/Server';
+import Utils from '../utils/Utils';
+
+const MODULE_NAME = 'AsyncTaskBuilder';
+
+export default class AsyncTaskBuilder {
+ public static async createAndSaveAsyncTasks(asyncTask: Omit<AsyncTask, 'id'>): Promise<void> {
+ // Check
+ if (Utils.isNullOrUndefined(asyncTask)) {
+ throw new Error('The asynchronous task must not be null');
+ }
+ // Check
+ if (Utils.isNullOrUndefined(asyncTask.name)) {
+ throw new Error('The Name of the asynchronous task is mandatory');
+ }
+ if (!Utils.isNullOrUndefined(asyncTask.parameters) && (typeof asyncTask.parameters !== 'object')) {
+ throw new Error('The Parameters of the asynchronous task must be a Json document');
+ }
+ // Set
+ asyncTask.status = AsyncTaskStatus.PENDING;
+ asyncTask.createdOn = new Date();
+ // Save
+ await AsyncTaskStorage.saveAsyncTask(asyncTask as AsyncTask);
+ // Log
+ await Logging.logInfo({
+ tenantID: Constants.DEFAULT_TENANT,
+ action: ServerAction.ASYNC_TASK,
+ module: MODULE_NAME, method: 'createAndSaveAsyncTasks',
+ message: `The asynchronous task '${asyncTask.name}' has been saved successfully and will be processed soon`
+ });
+ }
+}

MODIFY
src/async-task/AsyncTaskManager.ts
src/async-task/AsyncTaskManager.ts
@@ -225,30 +225,4 @@ export default class AsyncTaskManager {
}
}
}
-
- public static async createAndSaveAsyncTasks(asyncTask: Omit<AsyncTask, 'id'>): Promise<void> {
- // Check
- if (Utils.isNullOrUndefined(asyncTask)) {
- throw new Error('The asynchronous task must not be null');
- }
- // Check
- if (Utils.isNullOrUndefined(asyncTask.name)) {
- throw new Error('The Name of the asynchronous task is mandatory');
- }
- if (!Utils.isNullOrUndefined(asyncTask.parameters) && (typeof asyncTask.parameters !== 'object')) {
- throw new Error('The Parameters of the asynchronous task must be a Json document');
- }
- // Set
- asyncTask.status = AsyncTaskStatus.PENDING;
- asyncTask.createdOn = new Date();
- // Save
- await AsyncTaskStorage.saveAsyncTask(asyncTask as AsyncTask);
- // Log
- await Logging.logInfo({
- tenantID: Constants.DEFAULT_TENANT,
- action: ServerAction.ASYNC_TASK,
- module: MODULE_NAME, method: 'createAndSaveAsyncTasks',
- message: `The asynchronous task '${asyncTask.name}' has been saved successfully and will be processed soon`
- });
- }
}

MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -5,7 +5,7 @@ import FeatureToggles, { Feature } from '../../../utils/FeatureToggles';
import StripeHelpers, { StripeChargeOperationResult } from './StripeHelpers';
import Transaction, { StartTransactionErrorCode } from '../../../types/Transaction';
-import AsyncTaskManager from '../../../async-task/AsyncTaskManager';
+import AsyncTaskBuilder from '../../../async-task/AsyncTaskBuilder';
import AxiosFactory from '../../../utils/AxiosFactory';
import { AxiosInstance } from 'axios';
import BackendError from '../../../exception/BackendError';
@@ -907,7 +907,7 @@ export default class StripeBillingIntegration extends BillingIntegration {
}
}
// Create and Save async task
- await AsyncTaskManager.createAndSaveAsyncTasks({
+ await AsyncTaskBuilder.createAndSaveAsyncTasks({
name: AsyncTasks.BILL_TRANSACTION,
action: ServerAction.BILLING_TRANSACTION,
type: AsyncTaskType.TASK,

MODIFY
src/server/ocpp/utils/OCPPUtils.ts
src/server/ocpp/utils/OCPPUtils.ts
import { BillingDataTransactionStart, BillingDataTransactionStop } from '../../../types/Billing';
import { ChargingProfile, ChargingProfilePurposeType } from '../../../types/ChargingProfile';
-import ChargingStation, { ChargingStationCapabilities, ChargingStationOcppParameters, ChargingStationTemplate, Command, Connector, ConnectorCurrentLimitSource, CurrentType, OcppParameter, SiteAreaLimitSource, StaticLimitAmps, TemplateUpdate, TemplateUpdateResult } from '../../../types/ChargingStation';
-import { OCPPChangeConfigurationCommandResult, OCPPChargingProfileStatus, OCPPConfigurationStatus, OCPPGetConfigurationCommandParam, OCPPGetConfigurationCommandResult, OCPPResetCommandResult, OCPPResetStatus, OCPPResetType } from '../../../types/ocpp/OCPPClient';
+import ChargingStation, { ChargingStationCapabilities, ChargingStationTemplate, Command, Connector, ConnectorCurrentLimitSource, CurrentType, OcppParameter, SiteAreaLimitSource, StaticLimitAmps, TemplateUpdate, TemplateUpdateResult } from '../../../types/ChargingStation';
+import { OCPPChangeConfigurationCommandResult, OCPPChargingProfileStatus, OCPPConfigurationStatus } from '../../../types/ocpp/OCPPClient';
import { OCPPMeasurand, OCPPNormalizedMeterValue, OCPPPhase, OCPPReadingContext, OCPPStopTransactionRequestExtended, OCPPUnitOfMeasure, OCPPValueFormat } from '../../../types/ocpp/OCPPServer';
import { OICPIdentification, OICPSessionID } from '../../../types/oicp/OICPIdentification';
import Tenant, { TenantComponents } from '../../../types/Tenant';
@@ -10,7 +10,6 @@ import Transaction, { InactivityStatus, TransactionAction } from '../../../types
import { ActionsResponse } from '../../../types/GlobalType';
import BackendError from '../../../exception/BackendError';
import BillingFactory from '../../../integration/billing/BillingFactory';
-import ChargingStationClientFactory from '../../../client/ocpp/ChargingStationClientFactory';
import ChargingStationStorage from '../../../storage/mongodb/ChargingStationStorage';
import ChargingStationVendorFactory from '../../../integration/charging-station-vendor/ChargingStationVendorFactory';
import Constants from '../../../utils/Constants';

MODIFY
src/server/rest/v1/service/CarService.ts
src/server/rest/v1/service/CarService.ts
@@ -7,7 +7,7 @@ import Tenant, { TenantComponents } from '../../../../types/Tenant';
import AppAuthError from '../../../../exception/AppAuthError';
import AppError from '../../../../exception/AppError';
-import AsyncTaskManager from '../../../../async-task/AsyncTaskManager';
+import AsyncTaskBuilder from '../../../../async-task/AsyncTaskBuilder';
import AuthorizationService from './AuthorizationService';
import Authorizations from '../../../../authorization/Authorizations';
import { Car } from '../../../../types/Car';
@@ -165,7 +165,7 @@ export default class CarService {
}
try {
// Create and Save async task
- await AsyncTaskManager.createAndSaveAsyncTasks({
+ await AsyncTaskBuilder.createAndSaveAsyncTasks({
name: AsyncTasks.SYNCHRONIZE_CAR_CATALOGS,
action,
type: AsyncTaskType.TASK,

MODIFY
src/server/rest/v1/service/OCPIEndpointService.ts
src/server/rest/v1/service/OCPIEndpointService.ts
@@ -5,7 +5,7 @@ import { NextFunction, Request, Response } from 'express';
import AppAuthError from '../../../../exception/AppAuthError';
import AppError from '../../../../exception/AppError';
-import AsyncTaskManager from '../../../../async-task/AsyncTaskManager';
+import AsyncTaskBuilder from '../../../../async-task/AsyncTaskBuilder';
import Authorizations from '../../../../authorization/Authorizations';
import Constants from '../../../../utils/Constants';
import LockingHelper from '../../../../locking/LockingHelper';
@@ -267,7 +267,7 @@ export default class OCPIEndpointService {
}
try {
// Create and Save async task
- await AsyncTaskManager.createAndSaveAsyncTasks({
+ await AsyncTaskBuilder.createAndSaveAsyncTasks({
name: AsyncTasks.OCPI_PULL_LOCATIONS,
action,
type: AsyncTaskType.TASK,
@@ -317,7 +317,7 @@ export default class OCPIEndpointService {
}
try {
// Create and Save async task
- await AsyncTaskManager.createAndSaveAsyncTasks({
+ await AsyncTaskBuilder.createAndSaveAsyncTasks({
name: AsyncTasks.OCPI_PULL_SESSIONS,
action,
type: AsyncTaskType.TASK,
@@ -367,7 +367,7 @@ export default class OCPIEndpointService {
}
try {
// Create and Save async task
- await AsyncTaskManager.createAndSaveAsyncTasks({
+ await AsyncTaskBuilder.createAndSaveAsyncTasks({
name: AsyncTasks.OCPI_PULL_TOKENS,
action,
type: AsyncTaskType.TASK,
@@ -417,7 +417,7 @@ export default class OCPIEndpointService {
}
try {
// Create and Save async task
- await AsyncTaskManager.createAndSaveAsyncTasks({
+ await AsyncTaskBuilder.createAndSaveAsyncTasks({
name: AsyncTasks.OCPI_PULL_CDRS,
action,
type: AsyncTaskType.TASK,
@@ -467,7 +467,7 @@ export default class OCPIEndpointService {
}
try {
// Create and Save async task
- await AsyncTaskManager.createAndSaveAsyncTasks({
+ await AsyncTaskBuilder.createAndSaveAsyncTasks({
name: AsyncTasks.OCPI_CHECK_CDRS,
action,
type: AsyncTaskType.TASK,
@@ -517,7 +517,7 @@ export default class OCPIEndpointService {
}
try {
// Create and Save async task
- await AsyncTaskManager.createAndSaveAsyncTasks({
+ await AsyncTaskBuilder.createAndSaveAsyncTasks({
name: AsyncTasks.OCPI_CHECK_SESSIONS,
action,
type: AsyncTaskType.TASK,
@@ -567,7 +567,7 @@ export default class OCPIEndpointService {
}
try {
// Create and Save async task
- await AsyncTaskManager.createAndSaveAsyncTasks({
+ await AsyncTaskBuilder.createAndSaveAsyncTasks({
name: AsyncTasks.OCPI_CHECK_LOCATIONS,
action,
type: AsyncTaskType.TASK,
@@ -617,7 +617,7 @@ export default class OCPIEndpointService {
}
try {
// Create and Save async task
- await AsyncTaskManager.createAndSaveAsyncTasks({
+ await AsyncTaskBuilder.createAndSaveAsyncTasks({
name: AsyncTasks.OCPI_PUSH_EVSE_STATUSES,
action,
type: AsyncTaskType.TASK,
@@ -668,7 +668,7 @@ export default class OCPIEndpointService {
}
try {
// Create and Save async task
- await AsyncTaskManager.createAndSaveAsyncTasks({
+ await AsyncTaskBuilder.createAndSaveAsyncTasks({
name: AsyncTasks.OCPI_PUSH_TOKENS,
action,
type: AsyncTaskType.TASK,

MODIFY
src/server/rest/v1/service/TagService.ts
src/server/rest/v1/service/TagService.ts
@@ -9,7 +9,7 @@ import Tenant, { TenantComponents } from '../../../../types/Tenant';
import AppAuthError from '../../../../exception/AppAuthError';
import AppError from '../../../../exception/AppError';
-import AsyncTaskManager from '../../../../async-task/AsyncTaskManager';
+import AsyncTaskBuilder from '../../../../async-task/AsyncTaskBuilder';
import AuthorizationService from './AuthorizationService';
import Authorizations from '../../../../authorization/Authorizations';
import Busboy from 'busboy';
@@ -524,7 +524,7 @@ export default class TagService {
`No Tag have been uploaded in ${executionDurationSecs}s`, req.user
);
// Create and Save async task
- await AsyncTaskManager.createAndSaveAsyncTasks({
+ await AsyncTaskBuilder.createAndSaveAsyncTasks({
name: AsyncTasks.TAGS_IMPORT,
action: ServerAction.TAGS_IMPORT,
type: AsyncTaskType.TASK,

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -10,7 +10,7 @@ import User, { ImportedUser, UserRequiredImportProperties } from '../../../../ty
import AppAuthError from '../../../../exception/AppAuthError';
import AppError from '../../../../exception/AppError';
-import AsyncTaskManager from '../../../../async-task/AsyncTaskManager';
+import AsyncTaskBuilder from '../../../../async-task/AsyncTaskBuilder';
import AuthorizationService from './AuthorizationService';
import Authorizations from '../../../../authorization/Authorizations';
import BillingFactory from '../../../../integration/billing/BillingFactory';
@@ -521,7 +521,7 @@ export default class UserService {
`No User have been uploaded in ${executionDurationSecs}s`, req.user
);
// Create and Save async task
- await AsyncTaskManager.createAndSaveAsyncTasks({
+ await AsyncTaskBuilder.createAndSaveAsyncTasks({
name: AsyncTasks.USERS_IMPORT,
action: ServerAction.USERS_IMPORT,
type: AsyncTaskType.TASK,

Removed circular deps between AsyncTaskManager -> *