Skip to content

Commit

Permalink
fix(opcua): Properly stop connector
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerni10 committed Jun 21, 2023
1 parent 2a2b6be commit a7eef11
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
7 changes: 7 additions & 0 deletions backend/src/south/south-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -325,6 +328,10 @@ export default class SouthConnector {

async stop(): Promise<void> {
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$) {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/south/south-opcua-da/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions backend/src/south/south-opcua-da/south-opcua-da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ export default class SouthOPCUADA extends SouthConnector {
*/
async connectToOpcuaServer(): Promise<void> {
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,
Expand Down
4 changes: 2 additions & 2 deletions backend/src/south/south-opcua-ha/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
15 changes: 7 additions & 8 deletions backend/src/south/south-opcua-ha/south-opcua-ha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -94,13 +94,12 @@ export default class SouthOPCUAHA extends SouthConnector {
*/
async connectToOpcuaServer(): Promise<void> {
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,
Expand Down Expand Up @@ -323,6 +322,7 @@ export default class SouthOPCUAHA extends SouthConnector {
}

async internalDisconnect(): Promise<void> {
this.disconnecting = true;
if (this.reconnectTimeout) {
clearTimeout(this.reconnectTimeout);
}
Expand All @@ -335,7 +335,6 @@ export default class SouthOPCUAHA extends SouthConnector {
}

override async disconnect(): Promise<void> {
this.disconnecting = true;
await this.internalDisconnect();
}
}

0 comments on commit a7eef11

Please sign in to comment.