From a7eef11d6477ba83e8abe4e656042004e4a4b441 Mon Sep 17 00:00:00 2001 From: burgerni10 Date: Tue, 18 Apr 2023 14:44:19 +0200 Subject: [PATCH] fix(opcua): Properly stop connector --- backend/src/south/south-connector.ts | 7 +++++++ backend/src/south/south-opcua-da/manifest.ts | 4 ++-- .../src/south/south-opcua-da/south-opcua-da.ts | 9 ++++----- backend/src/south/south-opcua-ha/manifest.ts | 4 ++-- .../src/south/south-opcua-ha/south-opcua-ha.ts | 15 +++++++-------- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/backend/src/south/south-connector.ts b/backend/src/south/south-connector.ts index 5ff3bd90de..f56397f81f 100644 --- a/backend/src/south/south-connector.ts +++ b/backend/src/south/south-connector.ts @@ -143,6 +143,9 @@ export default class SouthConnector { } addToQueue(scanMode: ScanModeDTO): void { + if (this.stopping) { + return; + } const foundJob = this.taskJobQueue.find(element => element.id === scanMode.id); if (foundJob) { // If a job is already scheduled in queue, it will not be added @@ -325,6 +328,10 @@ export default class SouthConnector { async stop(): Promise { this.stopping = true; + for (const cronJob of this.cronByScanModeIds.values()) { + cronJob.stop(); + } + this.cronByScanModeIds.clear(); this.logger.info(`Stopping South "${this.configuration.name}" (${this.configuration.id})...`); if (this.runProgress$) { diff --git a/backend/src/south/south-opcua-da/manifest.ts b/backend/src/south/south-opcua-da/manifest.ts index 1c4225de0a..0af4c8818e 100644 --- a/backend/src/south/south-opcua-da/manifest.ts +++ b/backend/src/south/south-opcua-da/manifest.ts @@ -34,7 +34,7 @@ const manifest: SouthConnectorManifest = { key: 'readTimeout', type: 'OibNumber', label: 'Read timeout (ms)', - defaultValue: 60_000, + defaultValue: 10_000, newRow: true, validators: [{ key: 'required' }, { key: 'min', params: { min: 1000 } }, { key: 'max', params: { max: 3_600_000 } }], readDisplay: false @@ -43,7 +43,7 @@ const manifest: SouthConnectorManifest = { key: 'retryInterval', type: 'OibNumber', label: 'Retry interval (ms)', - defaultValue: 10_000, + defaultValue: 5_000, newRow: false, validators: [{ key: 'required' }, { key: 'min', params: { min: 100 } }, { key: 'max', params: { max: 3_600_000 } }], readDisplay: false diff --git a/backend/src/south/south-opcua-da/south-opcua-da.ts b/backend/src/south/south-opcua-da/south-opcua-da.ts index 4560c42e04..9f761adbd0 100644 --- a/backend/src/south/south-opcua-da/south-opcua-da.ts +++ b/backend/src/south/south-opcua-da/south-opcua-da.ts @@ -78,13 +78,12 @@ export default class SouthOPCUADA extends SouthConnector { */ async connectToOpcuaServer(): Promise { try { - const connectionStrategy = { - initialDelay: 1000, - maxRetry: 1 - }; const options: OPCUAClientOptions = { applicationName: 'OIBus', - connectionStrategy, + connectionStrategy: { + initialDelay: 1000, + maxRetry: 1 + }, securityMode: MessageSecurityMode[this.configuration.settings.securityMode], securityPolicy: this.configuration.settings.securityPolicy, endpointMustExist: false, diff --git a/backend/src/south/south-opcua-ha/manifest.ts b/backend/src/south/south-opcua-ha/manifest.ts index 9d53ac83c8..feb589b157 100644 --- a/backend/src/south/south-opcua-ha/manifest.ts +++ b/backend/src/south/south-opcua-ha/manifest.ts @@ -34,7 +34,7 @@ const manifest: SouthConnectorManifest = { key: 'readTimeout', type: 'OibNumber', label: 'Read timeout (ms)', - defaultValue: 60_000, + defaultValue: 10_000, newRow: true, validators: [{ key: 'required' }, { key: 'min', params: { min: 1000 } }, { key: 'max', params: { max: 3_600_000 } }], readDisplay: false @@ -43,7 +43,7 @@ const manifest: SouthConnectorManifest = { key: 'retryInterval', type: 'OibNumber', label: 'Retry interval (ms)', - defaultValue: 10_000, + defaultValue: 5_000, newRow: false, validators: [{ key: 'required' }, { key: 'min', params: { min: 100 } }, { key: 'max', params: { max: 3_600_000 } }], readDisplay: false diff --git a/backend/src/south/south-opcua-ha/south-opcua-ha.ts b/backend/src/south/south-opcua-ha/south-opcua-ha.ts index 30b7dc0f00..1032982aa1 100644 --- a/backend/src/south/south-opcua-ha/south-opcua-ha.ts +++ b/backend/src/south/south-opcua-ha/south-opcua-ha.ts @@ -27,10 +27,10 @@ import fs from 'node:fs/promises'; import path from 'node:path'; const AGGREGATE_TYPES = ['raw', 'count', 'max', 'min', 'avg']; -type AggregateType = typeof AGGREGATE_TYPES[number]; +type AggregateType = (typeof AGGREGATE_TYPES)[number]; const RESAMPLINGS = ['none', '1s', '10s', '30s', '60s', '1h', '24h']; -type Resampling = typeof RESAMPLINGS[number]; +type Resampling = (typeof RESAMPLINGS)[number]; /** * Class SouthOPCUAHA - Connect to an OPCUA server in HA (Historian Access) mode @@ -94,13 +94,12 @@ export default class SouthOPCUAHA extends SouthConnector { */ async connectToOpcuaServer(): Promise { try { - const connectionStrategy = { - initialDelay: 1000, - maxRetry: 1 - }; const options: OPCUAClientOptions = { applicationName: 'OIBus', - connectionStrategy, + connectionStrategy: { + initialDelay: 1000, + maxRetry: 1 + }, securityMode: MessageSecurityMode[this.configuration.settings.securityMode], securityPolicy: this.configuration.settings.securityPolicy, endpointMustExist: false, @@ -323,6 +322,7 @@ export default class SouthOPCUAHA extends SouthConnector { } async internalDisconnect(): Promise { + this.disconnecting = true; if (this.reconnectTimeout) { clearTimeout(this.reconnectTimeout); } @@ -335,7 +335,6 @@ export default class SouthOPCUAHA extends SouthConnector { } override async disconnect(): Promise { - this.disconnecting = true; await this.internalDisconnect(); } }