Added lock in Async task manager + Add a Job that awakes the manager
MODIFY
src/async-task/AsyncTaskManager.ts
src/async-task/AsyncTaskManager.ts
@@ -57,6 +57,10 @@ 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,
@@ -213,6 +217,11 @@ export default class AsyncTaskManager {
message: 'No asynchronous task to process'
});
}
+ } finally {
+ // Release lock
+ await LockingManager.release(asyncTaskManagerLock);
+ }
+ }
}
}

MODIFY
src/locking/LockingHelper.ts
src/locking/LockingHelper.ts
@@ -24,6 +24,14 @@ export default class LockingHelper {
return lock;
}
+ public static async acquireAsyncTaskManagerLock(tenantID: string): Promise<Lock | null> {
+ const lock = LockingManager.createExclusiveLock(tenantID, LockEntity.ASYNC_TASK_MANAGER, 'async-task-manager', 24 * 60 * 60);
+ if (!(await LockingManager.acquire(lock))) {
+ return null;
+ }
+ return lock;
+ }
+
public static async acquireSiteAreaSmartChargingLock(tenantID: string, siteArea: SiteArea, timeoutSecs: number): Promise<Lock | null> {
const lock = LockingManager.createExclusiveLock(tenantID, LockEntity.SITE_AREA, `${siteArea.id}-smart-charging`, 180);
if (!(await LockingManager.acquire(lock, timeoutSecs))) {

MODIFY
src/scheduler/SchedulerManager.ts
src/scheduler/SchedulerManager.ts
import AssetGetConsumptionTask from './tasks/AssetGetConsumptionTask';
+import AsyncTaskCheckTask from './tasks/AsyncTaskCheckTask';
import BillingPeriodicOperationTask from './tasks/BillingPeriodicOperationTask';
import CheckAndComputeSmartChargingTask from './tasks/CheckAndComputeSmartChargingTask';
import CheckChargingStationTemplateTask from './tasks/CheckChargingStationTemplateTask';
@@ -61,6 +62,9 @@ export default class SchedulerManager {
let schedulerTask: SchedulerTask;
// Tasks
switch (task.name) {
+ case 'AsyncTaskCheckTask':
+ schedulerTask = new AsyncTaskCheckTask();
+ break;
case 'LoggingDatabaseTableCleanupTask':
schedulerTask = new LoggingDatabaseTableCleanupTask();
break;

ADD
src/scheduler/tasks/AsyncTaskCheckTask.ts
+import AsyncTaskManager from '../../async-task/AsyncTaskManager';
+import SchedulerTask from '../SchedulerTask';
+import { TaskConfig } from '../../types/TaskConfig';
+
+export default class AsyncTaskCheckTask extends SchedulerTask {
+ public async run(name: string, config: TaskConfig): Promise<void> {
+ // Check Async Manager
+ await AsyncTaskManager.handleAsyncTasks();
+ }
+}

MODIFY
src/types/Locking.ts
src/types/Locking.ts
@@ -31,5 +31,6 @@ export enum LockEntity {
TAG = 'tag',
OICP_ENDPOINT = 'oicp-endpoint',
ASYNC_TASK = 'async-task',
+ ASYNC_TASK_MANAGER = 'async-task-manager',
SCHEDULER_TASK = 'scheduler-task',
}

Added lock in Async task manager + Add a Job that awakes the manager