Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing in a promise that resolves to a request cache strategy for dictionary load #418

Merged
merged 10 commits into from
Jan 30, 2024
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 @@ -126,7 +129,8 @@ export default function install(configuration) {
pollQuestionParameter,
pollQuestionTelemetry,
realtimeTelemetryProvider,
configuration.yamcsProcessor
configuration.yamcsProcessor,
dictionaryRequestCacheStrategyPromise
);

openmct.objects.addRoot({
Expand Down
2 changes: 1 addition & 1 deletion src/providers/limit-provider.js
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a fix for a lint error that snuck in from a different, unrelated, PR.

Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default class LimitProvider {
const limits = domainObject.configuration.limits;

return {
limits: async () => limits
limits: () => Promise.resolve(limits)
};
}

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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

.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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have some other function like 'buildRequestOptions' that does this? I mean, we can always add it down the road, but it seems weird just assigning directly from the cache strategy promise.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i hear you. we could change it now or wait until there are other requests. this one is very specific to loading the dictionary so i think we may be okay.


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
Loading