Skip to content

Commit

Permalink
Adding abort signal for object and telemetry requests (#58)
Browse files Browse the repository at this point in the history
Bump to rc1

Co-authored-by: David Tsay <[email protected]>
  • Loading branch information
jvigliotta and davetsay authored Jul 7, 2023
1 parent e00c1be commit 6eaa524
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"mini-css-extract-plugin": "2.6.0",
"moment": "2.29.4",
"node-bourbon": "^4.2.3",
"openmct": "nasa/openmct#omm-r5.1.0-rc2",
"openmct": "nasa/openmct#omm-r5.1.0-rc3",
"openmct-legacy-support": "akhenry/openmct-legacy-support#omm-r5.1.0-rc1",
"printj": "^1.2.1",
"raw-loader": "^0.5.1",
Expand Down
20 changes: 11 additions & 9 deletions src/historical/HistoricalProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ define([
batchRequest: function (batch) {
const requests = _.values(batch.requestsById);
const params = requests[0].params;
const options = requests[0].options;

params.lad_type = params.sort;
params.select = '(dn,eu,channel_id,ert,scet,sclk,lst,record_type,dn_alarm_state,eu_alarm_state,module,realtime,dss_id)'
Expand All @@ -51,7 +52,7 @@ define([
requestURL = ladURL;
}

mcws.dataTable(requestURL)
mcws.dataTable(requestURL, { signal: options.signal })
.read(params)
.then(function (res) {
const valuesByChannelId = _.groupBy(res, 'channel_id');
Expand Down Expand Up @@ -89,6 +90,7 @@ define([
batchRequest: function (batch) {
const requests = _.values(batch.requestsById);
const params = requests[0].params;
const options = requests[0].options;

params.minmax = '(' +
[
Expand All @@ -101,7 +103,7 @@ define([
params.filter.channel_id__in = _.map(requests, 'domainObject.telemetry.channel_id');
setSortFilter(params);

mcws.dataTable(requests[0].domainObject.telemetry.channelMinMaxUrl)
mcws.dataTable(requests[0].domainObject.telemetry.channelMinMaxUrl, { signal: options.signal })
.read(params)
.then(function (res) {
const valuesByChannelId = _.groupBy(res, 'channel_id');
Expand Down Expand Up @@ -167,7 +169,7 @@ define([

setSortFilter(params);

return mcws.dataTable(url)
return mcws.dataTable(url, { signal: options.signal })
.read(params);
}
}, {
Expand All @@ -180,7 +182,7 @@ define([
setMaxResults(domainObject, options, params);
setSortFilter(params);

const promise = mcws.dataTable(domainObject.telemetry.dataProductUrl)
const promise = mcws.dataTable(domainObject.telemetry.dataProductUrl, { signal: options.signal })
.read(params);

if (domainObject.type === 'vista.dataProducts') {
Expand Down Expand Up @@ -229,7 +231,7 @@ define([
domainObject.telemetry.alarmLevel.toUpperCase();
}

const dataTable = mcws.dataTable(domainObject.telemetry.channelHistoricalUrl);
const dataTable = mcws.dataTable(domainObject.telemetry.channelHistoricalUrl, { signal: options.signal });

return Promise.all([
dataTable.read(dnQueryParams),
Expand Down Expand Up @@ -258,7 +260,7 @@ define([
delete params.filter[options.domain + '__gte'];
delete params.filter[options.domain + '__lte'];

return mcws.dataTable(domainObject.telemetry.commandEventUrl)
return mcws.dataTable(domainObject.telemetry.commandEventUrl, { signal: options.signal })
.read(params)
.then(function (res) {
return res;
Expand All @@ -279,7 +281,7 @@ define([
setMaxResults(domainObject, options, params);
setSortFilter(params);

return mcws.dataTable(domainObject.telemetry.channelHistoricalUrl)
return mcws.dataTable(domainObject.telemetry.channelHistoricalUrl, { signal: options.signal })
.read(params);
}
}];
Expand All @@ -301,7 +303,7 @@ define([
params.filter.channel_id__in = _.map(requests, 'domainObject.telemetry.channel_id');
setSortFilter(params);

mcws.dataTable(requests[0].domainObject.telemetry.channelHistoricalUrl)
mcws.dataTable(requests[0].domainObject.telemetry.channelHistoricalUrl, { signal: options.signal })
.read(params)
.then(function (res) {
const valuesByChannelId = _.groupBy(res, 'channel_id');
Expand All @@ -323,7 +325,7 @@ define([
setSortFilter(params);
setMaxResults(domainObject, options, params);

return mcws.dataTable(domainObject.telemetry.channelHistoricalUrl)
return mcws.dataTable(domainObject.telemetry.channelHistoricalUrl, { signal: options.signal })
.read(params);
}
};
Expand Down
11 changes: 8 additions & 3 deletions src/persistence/MCWSPersistenceProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default class MCWSPersistenceProvider {
*/
async get(identifier, abortSignal) {
const { key, namespace } = identifier;
const options = {};

// check if it is a namespace that has subnamespaces, if so, we return this item dynamically
if (identifier.key === 'container') {
Expand All @@ -91,7 +92,11 @@ export default class MCWSPersistenceProvider {
return createModelFromNamespaceDefinition('system', containerNamespace, containedNamespaceIdentifiers);
}

const persistenceNamespace = await this.#getNamespace(namespace);
if (abortSignal) {
options.signal = abortSignal;
}

const persistenceNamespace = await this.#getNamespace(namespace, options);

try {
let result = await persistenceNamespace.opaqueFile(key).read();
Expand Down Expand Up @@ -146,13 +151,13 @@ export default class MCWSPersistenceProvider {
return domainObject;
}

async #getNamespace(persistenceSpace) {
async #getNamespace(persistenceSpace, options) {
const persistenceNamespaces = await this.getPersistenceNamespaces();
const persistenceNamespace = persistenceNamespaces.find((namespace) => {
return namespace.key === persistenceSpace;
})

return mcws.namespace(persistenceNamespace.url);
return mcws.namespace(persistenceNamespace.url, options);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/services/mcws/DataTableMIO.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import MIO from './MIO';
*/

class DataTableMIO extends MIO {
constructor(url) {
constructor(url, options) {
super(url);

this.options = options;
this.type = 'datatable';
}

Expand Down
12 changes: 11 additions & 1 deletion src/services/mcws/MIO.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,17 @@ export default class MIO {
options.body = JSON.stringify(body);
}

return mcwsClient.request(options);
if (this.options?.signal) {
options.signal = this.options.signal;
}

return mcwsClient.request(options)
.catch(error => {
// suppress abort errors
if (error.name !== 'AbortError') {
throw error;
}
});
}

async getMetadata() {
Expand Down
9 changes: 5 additions & 4 deletions src/services/mcws/NamespaceMIO.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import DataTableMIO from './DataTableMIO';
* @augments MIO
*/
class NamespaceMIO extends MIO {
constructor(url) {
constructor(url, options) {
super(url);

this.options = options;
this.type = 'namespace';
}

Expand Down Expand Up @@ -46,7 +47,7 @@ class NamespaceMIO extends MIO {
* @returns {OpaqueFileMIO} a handle to the opaque file
*/
opaqueFile(name) {
return new OpaqueFileMIO(`${this.url}/${name}`);
return new OpaqueFileMIO(`${this.url}/${name}`, this.options);
}

/**
Expand All @@ -64,7 +65,7 @@ class NamespaceMIO extends MIO {
* @returns {NamespaceMIO} a handle to that namespace
*/
namespace(name) {
return new NamespaceMIO(`${this.url}/${name}`);
return new NamespaceMIO(`${this.url}/${name}`, this.options);
}

/**
Expand All @@ -79,7 +80,7 @@ class NamespaceMIO extends MIO {
* @returns {DataTableMIO} a handle to that datatable
*/
dataTable(name) {
return new DataTableMIO(`${this.url}/${name}`);
return new DataTableMIO(`${this.url}/${name}`, this.options);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/services/mcws/OpaqueFileMIO.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import MIO from './MIO';
*/

class OpaqueFileMIO extends MIO {
constructor(url) {
constructor(url, options) {
super(url);

this.options = options;
this.type = 'opaque_file';
}

Expand Down
12 changes: 6 additions & 6 deletions src/services/mcws/mcws.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ class MCWS {
client.configure(config);
}

namespace(name) {
return new NamespaceMIO(name);
namespace(name, options) {
return new NamespaceMIO(name, options);
}

dataTable(name) {
return new DataTableMIO(name);
dataTable(name, options) {
return new DataTableMIO(name, options);
}

opaqueFile(name) {
return new OpaqueFileMIO(name);
opaqueFile(name, options) {
return new OpaqueFileMIO(name, options);
}
}

Expand Down

0 comments on commit 6eaa524

Please sign in to comment.