Skip to content

Commit

Permalink
Allow passing in a promise that resolves to a request cache strategy …
Browse files Browse the repository at this point in the history
…for dictionary load (#418)

* temporarily enable source maps

* pass in cacheStrategy to objectProvider

* remove unused parameters

* change cache strategy to be dynamic

* disable eval-source-map in prod

* lint fix

* fix lint error

* add README section explaining new feature

---------

Co-authored-by: John Hill <[email protected]>
  • Loading branch information
davetsay and unlikelyzero authored Jan 30, 2024
1 parent ef505ad commit c62d10a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,24 @@ openmct.install(installYamcsPlugin({
| yamcsInstance | The name of the instance configured in YAMCS that you wish to connect to. | myproject |
| yamcsFolder | The name of the instance configured in YAMCS that you wish to connect to. | myproject |

## dictionaryRequestCacheStrategyPromise
installYamcsPlugin also accepts an optional promise argument `dictionaryRequestCacheStrategyPromise`. This strategy is passed to the request for loading the YAMCS dictionary, or the `#loadTelemetryDictionary` function in `object-provider.js`. An example of how to make use of this is below.
```
let cacheStrategy;
const cacheStrategyPromise = new Promise(resolve => cacheStrategy)
openmct.install(installYamcsPlugin(
configuration,
cacheStrategryPromise
))
if (DICTIONARY_VERSION_IS_NEW) { // some check to determine dictionary version
cacheStrategy({cache: 'reload'})
} else {
cacheStrategy({})
}
```

## Special XTCE features

If you are using an XTCE configuration in Yamcs, there are two special
Expand Down
8 changes: 6 additions & 2 deletions src/openmct-yamcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ import PollQuestionParameter from './providers/user/poll-question-parameter.js';
import PollQuestionTelemetry from './providers/user/poll-question-telemetry.js';
import ExportToCSVActionPlugin from './actions/exportToCSV/plugin.js';

export default function install(configuration) {
export default function install(
configuration,
dictionaryRequestCacheStrategyPromise
) {
return (openmct) => {
openmct.install(openmct.plugins.ISOTimeFormat());

Expand Down Expand Up @@ -129,7 +132,8 @@ export default function install(configuration) {
pollQuestionParameter,
pollQuestionTelemetry,
realtimeTelemetryProvider,
configuration.yamcsProcessor
configuration.yamcsProcessor,
dictionaryRequestCacheStrategyPromise
);

openmct.objects.addRoot({
Expand Down
11 changes: 7 additions & 4 deletions src/providers/object-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const YAMCS_API_MAP = {
const operatorStatusParameter = new OperatorStatusParameter();

export default class YamcsObjectProvider {
constructor(openmct, url, instance, folderName, roleStatusTelemetry, pollQuestionParameter, pollQuestionTelemetry, realtimeTelemetryProvider, processor = 'realtime') {
constructor(openmct, url, instance, folderName, roleStatusTelemetry, pollQuestionParameter, pollQuestionTelemetry, realtimeTelemetryProvider, processor = 'realtime', dictionaryRequestCacheStrategyPromise = Promise.resolve({})) {
this.openmct = openmct;
this.url = url;
this.instance = instance;
Expand All @@ -52,6 +52,7 @@ export default class YamcsObjectProvider {
this.dictionary = {};
this.limitOverrides = {};
this.dictionaryPromise = null;
this.dictionaryRequestCacheStrategyPromise = dictionaryRequestCacheStrategyPromise;
this.roleStatusTelemetry = roleStatusTelemetry;
this.pollQuestionParameter = pollQuestionParameter;
this.pollQuestionTelemetry = pollQuestionTelemetry;
Expand Down Expand Up @@ -180,7 +181,7 @@ export default class YamcsObjectProvider {

#getTelemetryDictionary() {
if (!this.dictionaryPromise) {
this.dictionaryPromise = this.#loadTelemetryDictionary(this.url, this.instance, this.folderName)
this.dictionaryPromise = this.#loadTelemetryDictionary()
.finally(() => {
this.roleStatusTelemetry.dictionaryLoadComplete();
});
Expand All @@ -193,8 +194,10 @@ export default class YamcsObjectProvider {
const operation = 'parameters?details=yes&limit=1000';
const parameterUrl = this.url + 'api/mdb/' + this.instance + '/' + operation;
const url = this.#getMdbUrl('space-systems');
const spaceSystems = await accumulateResults(url, {}, 'spaceSystems', []);
const parameters = await accumulateResults(parameterUrl, {}, 'parameters', []);
const requestOptions = await this.dictionaryRequestCacheStrategyPromise;

const spaceSystems = await accumulateResults(url, requestOptions, 'spaceSystems', []);
const parameters = await accumulateResults(parameterUrl, requestOptions, 'parameters', []);

/* Sort the space systems by name, so that the
children of the root object are in sorted order. */
Expand Down

0 comments on commit c62d10a

Please sign in to comment.