Create basic Asset scheduler config
MODIFY
docker/config.json
docker/config.json
"active": false,
"periodicity": "0 0 1 * *",
"config": {}
+ },
+ {
+ "name": "AssetGetConsumptionTask",
+ "active": false,
+ "periodicity": "* * * * *",
+ "config": {}
}
]
},

MODIFY
src/locking/LockingHelper.ts
src/locking/LockingHelper.ts
@@ -27,4 +27,12 @@ export default class LockingHelper {
}
return lock;
}
+
+ public static async createAssetLock(tenantID: string): Promise<Lock|null> {
+ const lock = LockingManager.createExclusiveLock(tenantID, LockEntity.ASSET, 'asset-consumption');
+ if (!(await LockingManager.acquire(lock))) {
+ return null;
+ }
+ return lock;
+ }
}

ADD
src/scheduler/tasks/AssetGetConsumptionTask.ts
+import { TaskConfig } from '../../types/TaskConfig';
+import Tenant from '../../types/Tenant';
+import SchedulerTask from '../SchedulerTask';
+import Utils from '../../utils/Utils';
+import TenantComponents from '../../types/TenantComponents';
+import Logging from '../../utils/Logging';
+import { ServerAction } from '../../types/Server';
+import LockingHelper from '../../locking/LockingHelper';
+
+const MODULE_NAME = 'AssetGetConsumptionTask';
+
+export default class AssetGetConsumptionTask extends SchedulerTask {
+ async processTenant(tenant: Tenant, config: TaskConfig): Promise<void> {
+ // Check if Asset component is active
+ if (!Utils.isTenantComponentActive(tenant, TenantComponents.ASSET)) {
+ Logging.logDebug({
+ tenantID: tenant.id,
+ module: MODULE_NAME,
+ method: 'processTenant',
+ action: ServerAction.RETRIEVE_ASSET_CONSUMPTION,
+ message: 'Asset Inactive for this tenant. The task \'AssetGetConsumptionTask\' is skipped.'
+ });
+ // Skip execution
+ return;
+ }
+ const assetLock = await LockingHelper.createAssetLock(tenant.id);
+ }
+}

MODIFY
src/types/Locking.ts
src/types/Locking.ts
@@ -23,4 +23,5 @@ export enum LockEntity {
TRANSACTION = 'transaction',
CAR = 'car',
INVOICE = 'invoice',
+ ASSET = 'asset',
}

Create basic Asset scheduler config