Removed the global lock of the Async Task Manager
MODIFY
src/async-task/AsyncTaskManager.ts
src/async-task/AsyncTaskManager.ts
@@ -58,10 +58,6 @@ export default class AsyncTaskManager {
public static async handleAsyncTasks(): Promise<void> {
// Active?
if (AsyncTaskManager.asyncTaskConfig?.active) {
- // Get the lock
- const asyncTaskManagerLock = await LockingHelper.acquireAsyncTaskManagerLock(Constants.DEFAULT_TENANT);
- if (asyncTaskManagerLock) {
- try {
await Logging.logDebug({
tenantID: Constants.DEFAULT_TENANT,
action: ServerAction.ASYNC_TASK,
@@ -92,55 +88,7 @@ export default class AsyncTaskManager {
await Promise.map(asyncTasks.result,
async (asyncTask: AsyncTask) => {
// Tasks
- let abstractAsyncTask: AbstractAsyncTask;
- switch (asyncTask.name) {
- case AsyncTasks.BILL_TRANSACTION:
- abstractAsyncTask = new BillTransactionAsyncTask(asyncTask);
- break;
- case AsyncTasks.TAGS_IMPORT:
- abstractAsyncTask = new TagsImportAsyncTask(asyncTask);
- break;
- case AsyncTasks.USERS_IMPORT:
- abstractAsyncTask = new UsersImportAsyncTask(asyncTask);
- break;
- case AsyncTasks.SYNCHRONIZE_CAR_CATALOGS:
- abstractAsyncTask = new SynchronizeCarCatalogsAsyncTask(asyncTask);
- break;
- case AsyncTasks.OCPI_PUSH_TOKENS:
- abstractAsyncTask = new OCPIPushTokensAsyncTask(asyncTask);
- break;
- case AsyncTasks.OCPI_PULL_LOCATIONS:
- abstractAsyncTask = new OCPIPullLocationsAsyncTask(asyncTask);
- break;
- case AsyncTasks.OCPI_PULL_SESSIONS:
- abstractAsyncTask = new OCPIPullSessionsAsyncTask(asyncTask);
- break;
- case AsyncTasks.OCPI_PULL_CDRS:
- abstractAsyncTask = new OCPIPullCdrsAsyncTask(asyncTask);
- break;
- case AsyncTasks.OCPI_CHECK_CDRS:
- abstractAsyncTask = new OCPICheckCdrsAsyncTask(asyncTask);
- break;
- case AsyncTasks.OCPI_CHECK_SESSIONS:
- abstractAsyncTask = new OCPICheckSessionsAsyncTask(asyncTask);
- break;
- case AsyncTasks.OCPI_CHECK_LOCATIONS:
- abstractAsyncTask = new OCPICheckLocationsAsyncTask(asyncTask);
- break;
- case AsyncTasks.OCPI_PULL_TOKENS:
- abstractAsyncTask = new OCPIPullTokensAsyncTask(asyncTask);
- break;
- case AsyncTasks.OCPI_PUSH_EVSE_STATUSES:
- abstractAsyncTask = new OCPIPushEVSEStatusesAsyncTask(asyncTask);
- break;
- default:
- await Logging.logError({
- tenantID: Constants.DEFAULT_TENANT,
- action: ServerAction.ASYNC_TASK,
- module: MODULE_NAME, method: 'handleAsyncTasks',
- message: `The asynchronous task '${asyncTask.name}' is unknown`
- });
- }
+ const abstractAsyncTask = await AsyncTaskManager.createTask(asyncTask);
if (abstractAsyncTask) {
// Get the lock
const asyncTaskLock = await LockingHelper.acquireAsyncTaskLock(Constants.DEFAULT_TENANT, asyncTask.id);
@@ -190,7 +138,7 @@ export default class AsyncTaskManager {
tenantID: Constants.DEFAULT_TENANT,
module: MODULE_NAME, method: 'handleAsyncTasks',
action: ServerAction.ASYNC_TASK,
- message: `Error while running the asynchronous task '${asyncTask.name}': ${error.message}`,
+ message: `Error while running the asynchronous task '${asyncTask.name}': ${error.message as string}`,
detailedMessages: { error: error.stack, asyncTask }
});
} finally {
@@ -218,11 +166,44 @@ export default class AsyncTaskManager {
message: 'No asynchronous task to process'
});
}
- } finally {
- // Release lock
- await LockingManager.release(asyncTaskManagerLock);
}
}
+
+ private static async createTask(asyncTask: AsyncTask): Promise<AbstractAsyncTask> {
+ switch (asyncTask.name) {
+ case AsyncTasks.BILL_TRANSACTION:
+ return new BillTransactionAsyncTask(asyncTask);
+ case AsyncTasks.TAGS_IMPORT:
+ return new TagsImportAsyncTask(asyncTask);
+ case AsyncTasks.USERS_IMPORT:
+ return new UsersImportAsyncTask(asyncTask);
+ case AsyncTasks.SYNCHRONIZE_CAR_CATALOGS:
+ return new SynchronizeCarCatalogsAsyncTask(asyncTask);
+ case AsyncTasks.OCPI_PUSH_TOKENS:
+ return new OCPIPushTokensAsyncTask(asyncTask);
+ case AsyncTasks.OCPI_PULL_LOCATIONS:
+ return new OCPIPullLocationsAsyncTask(asyncTask);
+ case AsyncTasks.OCPI_PULL_SESSIONS:
+ return new OCPIPullSessionsAsyncTask(asyncTask);
+ case AsyncTasks.OCPI_PULL_CDRS:
+ return new OCPIPullCdrsAsyncTask(asyncTask);
+ case AsyncTasks.OCPI_CHECK_CDRS:
+ return new OCPICheckCdrsAsyncTask(asyncTask);
+ case AsyncTasks.OCPI_CHECK_SESSIONS:
+ return new OCPICheckSessionsAsyncTask(asyncTask);
+ case AsyncTasks.OCPI_CHECK_LOCATIONS:
+ return new OCPICheckLocationsAsyncTask(asyncTask);
+ case AsyncTasks.OCPI_PULL_TOKENS:
+ return new OCPIPullTokensAsyncTask(asyncTask);
+ case AsyncTasks.OCPI_PUSH_EVSE_STATUSES:
+ return new OCPIPushEVSEStatusesAsyncTask(asyncTask);
+ default:
+ await Logging.logError({
+ tenantID: Constants.DEFAULT_TENANT,
+ action: ServerAction.ASYNC_TASK,
+ module: MODULE_NAME, method: 'handleAsyncTasks',
+ message: `The asynchronous task '${asyncTask.name as string}' is unknown`
+ });
}
}
}

Removed the global lock of the Async Task Manager