Added push token job
Renamed OCPIGet* to OCPIPull*
MODIFY
docker/config-standalone.json
docker/config-standalone.json
"config": {}
},
{
- "name": "OCPIGetLocationsTask",
+ "name": "OCPIPullLocationsTask",
"active": false,
"periodicity": "*/10 * * * *",
"config": {}
},
{
- "name": "OCPIGetTokensTask",
+ "name": "OCPIPushTokensTask",
+ "active": true,
+ "periodicity": "0 0 1 * *"
+ },
+ {
+ "name": "OCPIPullTokensTask",
"active": false,
"periodicity": "0 2 * * *",
"config": {}
},
{
- "name": "OCPIGetSessionsTask",
+ "name": "OCPIPullSessionsTask",
"active": false,
"periodicity": "0 3 * * *",
"config": {}
},
{
- "name": "OCPIGetCdrsTask",
+ "name": "OCPIPullCdrsTask",
"active": false,
"periodicity": "0 4 * * *",
"config": {}

MODIFY
docker/config.json
docker/config.json
"config": {}
},
{
- "name": "OCPIGetLocationsTask",
+ "name": "OCPIPullLocationsTask",
"active": false,
"periodicity": "*/10 * * * *",
"config": {}
},
{
- "name": "OCPIGetTokensTask",
+ "name": "OCPIPullTokensTask",
"active": false,
"periodicity": "0 2 * * *",
"config": {}
},
{
- "name": "OCPIGetSessionsTask",
+ "name": "OCPIPushTokensTask",
+ "active": true,
+ "periodicity": "0 0 1 * *"
+ },
+ {
+ "name": "OCPIPullSessionsTask",
"active": false,
"periodicity": "0 3 * * *",
"config": {}
},
{
- "name": "OCPIGetCdrsTask",
+ "name": "OCPIPullCdrsTask",
"active": false,
"periodicity": "0 4 * * *",
"config": {}

MODIFY
src/scheduler/SchedulerManager.ts
src/scheduler/SchedulerManager.ts
@@ -18,10 +18,10 @@ import MigrateSensitiveDataTask from './tasks/MigrateSensitiveDataTask';
import OCPICheckCdrsTask from './tasks/ocpi/OCPICheckCdrsTask';
import OCPICheckLocationsTask from './tasks/ocpi/OCPICheckLocationsTask';
import OCPICheckSessionsTask from './tasks/ocpi/OCPICheckSessionsTask';
-import OCPIGetCdrsTask from './tasks/ocpi/OCPIGetCdrsTask';
-import OCPIGetLocationsTask from './tasks/ocpi/OCPIGetLocationsTask';
-import OCPIGetSessionsTask from './tasks/ocpi/OCPIGetSessionsTask';
-import OCPIGetTokensTask from './tasks/ocpi/OCPIGetTokensTask';
+import OCPIPullCdrsTask from './tasks/ocpi/OCPIPullCdrsTask';
+import OCPIPullLocationsTask from './tasks/ocpi/OCPIPullLocationsTask';
+import OCPIPullSessionsTask from './tasks/ocpi/OCPIPullSessionsTask';
+import OCPIPullTokensTask from './tasks/ocpi/OCPIPullTokensTask';
import OCPIPushCdrsTask from './tasks/ocpi/OCPIPushCdrsTask';
import OCPIPushEVSEStatusesTask from './tasks/ocpi/OCPIPushEVSEStatusesTask';
import OICPPushEvseDataTask from './tasks/oicp/OICPPushEvseDataTask';
@@ -103,20 +103,20 @@ export default class SchedulerManager {
return new OICPPushEvseStatusTask();
case 'OCPIPushEVSEStatusesTask':
return new OCPIPushEVSEStatusesTask();
- case 'OCPIGetCdrsTask':
- return new OCPIGetCdrsTask();
- case 'OCPIGetLocationsTask':
- return new OCPIGetLocationsTask();
- case 'OCPIGetSessionsTask':
- return new OCPIGetSessionsTask();
+ case 'OCPIPullCdrsTask':
+ return new OCPIPullCdrsTask();
+ case 'OCPIPullLocationsTask':
+ return new OCPIPullLocationsTask();
+ case 'OCPIPullSessionsTask':
+ return new OCPIPullSessionsTask();
case 'OCPICheckLocationsTask':
return new OCPICheckLocationsTask();
case 'OCPICheckSessionsTask':
return new OCPICheckSessionsTask();
case 'OCPICheckCdrsTask':
return new OCPICheckCdrsTask();
- case 'OCPIGetTokensTask':
- return new OCPIGetTokensTask();
+ case 'OCPIPullTokensTask':
+ return new OCPIPullTokensTask();
case 'OCPIPushCdrsTask':
return new OCPIPushCdrsTask();
case 'SynchronizeRefundTransactionsTask':

MODIFY
src/scheduler/tasks/ocpi/OCPICheckCdrsTask.ts
src/scheduler/tasks/ocpi/OCPICheckCdrsTask.ts
@@ -61,7 +61,7 @@ export default class OCPICheckCdrsTask extends TenantSchedulerTask {
tenantID: tenant.id,
module: MODULE_NAME, method: 'processOCPIEndpoint',
action: ServerAction.OCPI_CHECK_CDRS,
- message: `The check of CDRs for endpoint '${ocpiEndpoint.name}' is being processed...`
+ message: `Check of CDRs for endpoint '${ocpiEndpoint.name}' is being processed...`
});
// Build OCPI Client
const ocpiClient = await OCPIClientFactory.getCpoOcpiClient(tenant, ocpiEndpoint);
@@ -70,7 +70,7 @@ export default class OCPICheckCdrsTask extends TenantSchedulerTask {
tenantID: tenant.id,
module: MODULE_NAME, method: 'processOCPIEndpoint',
action: ServerAction.OCPI_CHECK_CDRS,
- message: `The check of CDRs for endpoint '${ocpiEndpoint.name}' is completed`,
+ message: `Check of CDRs for endpoint '${ocpiEndpoint.name}' is completed`,
detailedMessages: { result }
});
} catch (error) {

MODIFY
src/scheduler/tasks/ocpi/OCPICheckLocationsTask.ts
src/scheduler/tasks/ocpi/OCPICheckLocationsTask.ts
@@ -61,7 +61,7 @@ export default class OCPICheckLocationsTask extends TenantSchedulerTask {
tenantID: tenant.id,
module: MODULE_NAME, method: 'processOCPIEndpoint',
action: ServerAction.OCPI_CHECK_SESSIONS,
- message: `The check locations process for endpoint '${ocpiEndpoint.name}' is being processed`
+ message: `Check of Locations for endpoint '${ocpiEndpoint.name}' is being processed`
});
// Build OCPI Client
const ocpiClient = await OCPIClientFactory.getCpoOcpiClient(tenant, ocpiEndpoint);
@@ -70,7 +70,7 @@ export default class OCPICheckLocationsTask extends TenantSchedulerTask {
tenantID: tenant.id,
module: MODULE_NAME, method: 'processOCPIEndpoint',
action: ServerAction.OCPI_CHECK_SESSIONS,
- message: `The check locations process for endpoint '${ocpiEndpoint.name}' is completed`,
+ message: `Check of Locations for endpoint '${ocpiEndpoint.name}' is completed`,
detailedMessages: { result }
});
} catch (error) {

MODIFY
src/scheduler/tasks/ocpi/OCPICheckSessionsTask.ts
src/scheduler/tasks/ocpi/OCPICheckSessionsTask.ts
@@ -61,7 +61,7 @@ export default class OCPICheckSessionsTask extends TenantSchedulerTask {
tenantID: tenant.id,
module: MODULE_NAME, method: 'processOCPIEndpoint',
action: ServerAction.OCPI_CHECK_SESSIONS,
- message: `The check sessions process for endpoint '${ocpiEndpoint.name}' is being processed`
+ message: `Check of Sessions for endpoint '${ocpiEndpoint.name}' is being processed`
});
// Build OCPI Client
const ocpiClient = await OCPIClientFactory.getCpoOcpiClient(tenant, ocpiEndpoint);
@@ -70,7 +70,7 @@ export default class OCPICheckSessionsTask extends TenantSchedulerTask {
tenantID: tenant.id,
module: MODULE_NAME, method: 'processOCPIEndpoint',
action: ServerAction.OCPI_CHECK_SESSIONS,
- message: `The check sessions process for endpoint '${ocpiEndpoint.name}' is completed`,
+ message: `Check of Sessions for endpoint '${ocpiEndpoint.name}' is completed`,
detailedMessages: { result }
});
} catch (error) {

RENAME
src/scheduler/tasks/ocpi/OCPIGetCdrsTask.ts
src/scheduler/tasks/ocpi/OCPIPullCdrsTask.ts
@@ -14,9 +14,9 @@ import { TaskConfig } from '../../../types/TaskConfig';
import TenantSchedulerTask from '../../TenantSchedulerTask';
import Utils from '../../../utils/Utils';
-const MODULE_NAME = 'OCPIGetCdrsTask';
+const MODULE_NAME = 'OCPIPullCdrsTask';
-export default class OCPIGetCdrsTask extends TenantSchedulerTask {
+export default class OCPIPullCdrsTask extends TenantSchedulerTask {
public async processTenant(tenant: Tenant, config: TaskConfig): Promise<void> {
try {
// Check if OCPI component is active
@@ -62,7 +62,7 @@ export default class OCPIGetCdrsTask extends TenantSchedulerTask {
tenantID: tenant.id,
action: ServerAction.OCPI_PULL_CDRS,
module: MODULE_NAME, method: 'processOCPIEndpointatch',
- message: `The get CDRs process for endpoint '${ocpiEndpoint.name}' is being processed`
+ message: `Pull of CDRs for endpoint '${ocpiEndpoint.name}' is being processed`
});
// Build OCPI Client
const ocpiClient = await OCPIClientFactory.getEmspOcpiClient(tenant, ocpiEndpoint);
@@ -72,7 +72,7 @@ export default class OCPIGetCdrsTask extends TenantSchedulerTask {
tenantID: tenant.id,
action: ServerAction.OCPI_PULL_CDRS,
module: MODULE_NAME, method: 'processOCPIEndpoint',
- message: `The get CDRs process for endpoint '${ocpiEndpoint.name}' is completed`,
+ message: `Pull of CDRs for endpoint '${ocpiEndpoint.name}' is completed`,
detailedMessages: { result }
});
} catch (error) {

RENAME
src/scheduler/tasks/ocpi/OCPIGetLocationsTask.ts
src/scheduler/tasks/ocpi/OCPIPullLocationsTask.ts
-import { OCPIGetLocationsTaskConfig, TaskConfig } from '../../../types/TaskConfig';
+import { OCPIPullLocationsTaskConfig, TaskConfig } from '../../../types/TaskConfig';
import Tenant, { TenantComponents } from '../../../types/Tenant';
import Constants from '../../../utils/Constants';
@@ -14,9 +14,9 @@ import { ServerAction } from '../../../types/Server';
import TenantSchedulerTask from '../../TenantSchedulerTask';
import Utils from '../../../utils/Utils';
-const MODULE_NAME = 'OCPIGetLocationsTask';
+const MODULE_NAME = 'OCPIPullLocationsTask';
-export default class OCPIGetLocationsTask extends TenantSchedulerTask {
+export default class OCPIPullLocationsTask extends TenantSchedulerTask {
public async processTenant(tenant: Tenant, config: TaskConfig): Promise<void> {
try {
// Check if OCPI component is active
@@ -33,7 +33,7 @@ export default class OCPIGetLocationsTask extends TenantSchedulerTask {
}
}
- private async processOCPIEndpoint(tenant: Tenant, ocpiEndpoint: OCPIEndpoint, config: OCPIGetLocationsTaskConfig): Promise<void> {
+ private async processOCPIEndpoint(tenant: Tenant, ocpiEndpoint: OCPIEndpoint, config: OCPIPullLocationsTaskConfig): Promise<void> {
// Get the lock
const ocpiLock = await LockingHelper.createOCPIPullLocationsLock(tenant.id, ocpiEndpoint);
if (ocpiLock) {
@@ -61,7 +61,7 @@ export default class OCPIGetLocationsTask extends TenantSchedulerTask {
tenantID: tenant.id,
action: ServerAction.OCPI_PULL_LOCATIONS,
module: MODULE_NAME, method: 'processOCPIEndpoint',
- message: `The get Locations process for endpoint '${ocpiEndpoint.name}' is being processed`
+ message: `Pull of Locations for endpoint '${ocpiEndpoint.name}' is being processed`
});
// Build OCPI Client
const ocpiClient = await OCPIClientFactory.getEmspOcpiClient(tenant, ocpiEndpoint);
@@ -71,7 +71,7 @@ export default class OCPIGetLocationsTask extends TenantSchedulerTask {
tenantID: tenant.id,
action: ServerAction.OCPI_PULL_LOCATIONS,
module: MODULE_NAME, method: 'processOCPIEndpoint',
- message: `The get Locations process for endpoint '${ocpiEndpoint.name}' is completed`,
+ message: `Pull of Locations process for endpoint '${ocpiEndpoint.name}' is completed`,
detailedMessages: { result }
});
} catch (error) {

RENAME
src/scheduler/tasks/ocpi/OCPIGetSessionsTask.ts
src/scheduler/tasks/ocpi/OCPIPullSessionsTask.ts
@@ -14,9 +14,9 @@ import { TaskConfig } from '../../../types/TaskConfig';
import TenantSchedulerTask from '../../TenantSchedulerTask';
import Utils from '../../../utils/Utils';
-const MODULE_NAME = 'OCPIGetSessionsTask';
+const MODULE_NAME = 'OCPIPullSessionsTask';
-export default class OCPIGetSessionsTask extends TenantSchedulerTask {
+export default class OCPIPullSessionsTask extends TenantSchedulerTask {
public async processTenant(tenant: Tenant, config: TaskConfig): Promise<void> {
try {
// Check if OCPI component is active
@@ -61,7 +61,7 @@ export default class OCPIGetSessionsTask extends TenantSchedulerTask {
tenantID: tenant.id,
module: MODULE_NAME, method: 'processOCPIEndpoint',
action: ServerAction.OCPI_PULL_SESSIONS,
- message: `The get sessions process for endpoint '${ocpiEndpoint.name}' is being processed`
+ message: `Pull of Sessions for endpoint '${ocpiEndpoint.name}' is being processed`
});
// Build OCPI Client
const ocpiClient = await OCPIClientFactory.getEmspOcpiClient(tenant, ocpiEndpoint);
@@ -71,7 +71,7 @@ export default class OCPIGetSessionsTask extends TenantSchedulerTask {
tenantID: tenant.id,
module: MODULE_NAME, method: 'processOCPIEndpoint',
action: ServerAction.OCPI_PULL_SESSIONS,
- message: `The get sessions process for endpoint '${ocpiEndpoint.name}' is completed`,
+ message: `Pull of Sessions for endpoint '${ocpiEndpoint.name}' is completed`,
detailedMessages: { result }
});
} catch (error) {

RENAME
src/scheduler/tasks/ocpi/OCPIGetTokensTask.ts
src/scheduler/tasks/ocpi/OCPIPullTokensTask.ts
-import { OCPIGetTokensTaskConfig, TaskConfig } from '../../../types/TaskConfig';
+import { OCPIPullTokensTaskConfig, TaskConfig } from '../../../types/TaskConfig';
import Tenant, { TenantComponents } from '../../../types/Tenant';
import Constants from '../../../utils/Constants';
@@ -14,9 +14,9 @@ import { ServerAction } from '../../../types/Server';
import TenantSchedulerTask from '../../TenantSchedulerTask';
import Utils from '../../../utils/Utils';
-const MODULE_NAME = 'OCPIGetTokensTask';
+const MODULE_NAME = 'OCPIPullTokensTask';
-export default class OCPIGetTokensTask extends TenantSchedulerTask {
+export default class OCPIPullTokensTask extends TenantSchedulerTask {
public async processTenant(tenant: Tenant, config: TaskConfig): Promise<void> {
try {
// Check if OCPI component is active
@@ -33,7 +33,7 @@ export default class OCPIGetTokensTask extends TenantSchedulerTask {
}
}
- private async processOCPIEndpoint(tenant: Tenant, ocpiEndpoint: OCPIEndpoint, config: OCPIGetTokensTaskConfig): Promise<void> {
+ private async processOCPIEndpoint(tenant: Tenant, ocpiEndpoint: OCPIEndpoint, config: OCPIPullTokensTaskConfig): Promise<void> {
// Get the lock
const ocpiLock = await LockingHelper.createOCPIPullTokensLock(tenant.id, ocpiEndpoint, config.partial);
if (ocpiLock) {
@@ -61,7 +61,7 @@ export default class OCPIGetTokensTask extends TenantSchedulerTask {
tenantID: tenant.id,
module: MODULE_NAME, method: 'processOCPIEndpoint',
action: ServerAction.OCPI_PULL_TOKENS,
- message: `The pull tokens process for endpoint '${ocpiEndpoint.name}' is being processed${config.partial ? ' (only diff)' : ' (full)'}...`
+ message: `Pull of Tokens for endpoint '${ocpiEndpoint.name}' is being processed${config.partial ? ' (only diff)' : ' (full)'}...`
});
// Build OCPI Client
const ocpiClient = await OCPIClientFactory.getCpoOcpiClient(tenant, ocpiEndpoint);
@@ -71,7 +71,7 @@ export default class OCPIGetTokensTask extends TenantSchedulerTask {
tenantID: tenant.id,
module: MODULE_NAME, method: 'processOCPIEndpoint',
action: ServerAction.OCPI_PULL_TOKENS,
- message: `The pull tokens process for endpoint '${ocpiEndpoint.name}' has been completed${config.partial ? ' (only diff)' : ' (full)'}`,
+ message: `Pull of Tokens for endpoint '${ocpiEndpoint.name}' has been completed${config.partial ? ' (only diff)' : ' (full)'}`,
detailedMessages: { result }
});
} catch (error) {

MODIFY
src/scheduler/tasks/ocpi/OCPIPushEVSEStatusesTask.ts
src/scheduler/tasks/ocpi/OCPIPushEVSEStatusesTask.ts
@@ -61,7 +61,7 @@ export default class OCPIPushEVSEStatusesTask extends TenantSchedulerTask {
tenantID: tenant.id,
module: MODULE_NAME, method: 'processOCPIEndpoint',
action: ServerAction.OCPI_PUSH_EVSE_STATUSES,
- message: `The push Locations process for endpoint '${ocpiEndpoint.name}' is being processed`
+ message: `Push of Locations for endpoint '${ocpiEndpoint.name}' is being processed`
});
// Build OCPI Client
const ocpiClient = await OCPIClientFactory.getCpoOcpiClient(tenant, ocpiEndpoint);
@@ -71,7 +71,7 @@ export default class OCPIPushEVSEStatusesTask extends TenantSchedulerTask {
tenantID: tenant.id,
module: MODULE_NAME, method: 'processOCPIEndpoint',
action: ServerAction.OCPI_PUSH_EVSE_STATUSES,
- message: `The push Locations process for endpoint '${ocpiEndpoint.name}' is completed (Success: ${sendResult.success} / Failure: ${sendResult.failure})`
+ message: `Push of Locations process for endpoint '${ocpiEndpoint.name}' is completed (Success: ${sendResult.success} / Failure: ${sendResult.failure})`
});
} catch (error) {
// Log error

ADD
src/scheduler/tasks/ocpi/OCPIPushTokensTask.ts
+import { OCPIPullLocationsTaskConfig, TaskConfig } from '../../../types/TaskConfig';
+import Tenant, { TenantComponents } from '../../../types/Tenant';
+
+import Constants from '../../../utils/Constants';
+import LockingHelper from '../../../locking/LockingHelper';
+import LockingManager from '../../../locking/LockingManager';
+import Logging from '../../../utils/Logging';
+import OCPIClientFactory from '../../../client/ocpi/OCPIClientFactory';
+import OCPIEndpoint from '../../../types/ocpi/OCPIEndpoint';
+import OCPIEndpointStorage from '../../../storage/mongodb/OCPIEndpointStorage';
+import { OCPIRegistrationStatus } from '../../../types/ocpi/OCPIRegistrationStatus';
+import { OCPIRole } from '../../../types/ocpi/OCPIRole';
+import { ServerAction } from '../../../types/Server';
+import TenantSchedulerTask from '../../TenantSchedulerTask';
+import Utils from '../../../utils/Utils';
+
+const MODULE_NAME = 'OCPIPushTokensTask';
+
+export default class OCPIPushTokensTask extends TenantSchedulerTask {
+ public async processTenant(tenant: Tenant, config: TaskConfig): Promise<void> {
+ try {
+ // Check if OCPI component is active
+ if (Utils.isTenantComponentActive(tenant, TenantComponents.OCPI)) {
+ // Get all available endpoints
+ const ocpiEndpoints = await OCPIEndpointStorage.getOcpiEndpoints(tenant, { role: OCPIRole.EMSP }, Constants.DB_PARAMS_MAX_LIMIT);
+ for (const ocpiEndpoint of ocpiEndpoints.result) {
+ await this.processOCPIEndpoint(tenant, ocpiEndpoint, config);
+ }
+ }
+ } catch (error) {
+ // Log error
+ await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_PUSH_TOKENS, error);
+ }
+ }
+
+ private async processOCPIEndpoint(tenant: Tenant, ocpiEndpoint: OCPIEndpoint, config: OCPIPullLocationsTaskConfig): Promise<void> {
+ // Get the lock
+ const ocpiLock = await LockingHelper.createOCPIPushTokensLock(tenant.id, ocpiEndpoint);
+ if (ocpiLock) {
+ try {
+ // Check if OCPI endpoint is registered
+ if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) {
+ await Logging.logDebug({
+ tenantID: tenant.id,
+ action: ServerAction.OCPI_PUSH_TOKENS,
+ module: MODULE_NAME, method: 'processOCPIEndpoint',
+ message: `The OCPI endpoint '${ocpiEndpoint.name}' is not registered. Skipping the OCPI endpoint.`
+ });
+ return;
+ }
+ if (!ocpiEndpoint.backgroundPatchJob) {
+ await Logging.logDebug({
+ tenantID: tenant.id,
+ action: ServerAction.OCPI_PUSH_TOKENS,
+ module: MODULE_NAME, method: 'processOCPIEndpoint',
+ message: `The OCPI endpoint '${ocpiEndpoint.name}' is inactive.`
+ });
+ return;
+ }
+ await Logging.logInfo({
+ tenantID: tenant.id,
+ action: ServerAction.OCPI_PUSH_TOKENS,
+ module: MODULE_NAME, method: 'processOCPIEndpoint',
+ message: `Push of Tokens for endpoint '${ocpiEndpoint.name}' is being processed`
+ });
+ // Build OCPI Client
+ const ocpiClient = await OCPIClientFactory.getEmspOcpiClient(tenant, ocpiEndpoint);
+ // Push the Tokens
+ const result = await ocpiClient.pushTokens();
+ await Logging.logInfo({
+ tenantID: tenant.id,
+ action: ServerAction.OCPI_PUSH_TOKENS,
+ module: MODULE_NAME, method: 'processOCPIEndpoint',
+ message: `Push of Tokens for endpoint '${ocpiEndpoint.name}' is completed`,
+ detailedMessages: { result }
+ });
+ } catch (error) {
+ // Log error
+ await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_PUSH_TOKENS, error);
+ } finally {
+ // Release the lock
+ await LockingManager.release(ocpiLock);
+ }
+ }
+ }
+}
+

MODIFY
src/types/TaskConfig.ts
src/types/TaskConfig.ts
@@ -28,11 +28,11 @@ export interface BillingPeriodicOperationTaskConfig extends TaskConfig {
attemptPayment?: boolean;
}
-export interface OCPIGetTokensTaskConfig extends TaskConfig {
+export interface OCPIPullTokensTaskConfig extends TaskConfig {
partial?: boolean;
}
-export interface OCPIGetLocationsTaskConfig extends TaskConfig {
+export interface OCPIPullLocationsTaskConfig extends TaskConfig {
partial?: boolean;
}

Added push token job
Renamed OCPIGet* to OCPIPull*