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

abort batched latest requests #363

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/providers/historical-telemetry-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class YamcsHistoricalTelemetryProvider {
this.standardizeOptions(options, domainObject);
if ((options.strategy === 'latest') && options.timeContext?.isRealTime()) {
// Latest requested in realtime, use latest telemetry provider instead
const mctDatum = await this.latestTelemetryProvider.requestLatest(domainObject);
const mctDatum = await this.latestTelemetryProvider.requestLatest(domainObject, options);

return [mctDatum];
}
Expand Down
38 changes: 32 additions & 6 deletions src/providers/latest-telemetry-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@ const BATCH_DEBOUNCE_MS = 100;
export default class LatestTelemetryProvider {
#bulkPromise;
#batchIds;
#batchAbortSignals;
#openmct;

constructor({url, instance, processor = 'realtime', openmct}) {
this.url = url;
this.instance = instance;
this.processor = processor;
this.#batchIds = [];
this.#batchAbortSignals = [];
this.#openmct = openmct;
}
async requestLatest(domainObject) {
async requestLatest(domainObject, options) {
const yamcsId = idToQualifiedName(domainObject.identifier.key);
this.#batchIds.push(yamcsId);
this.#batchAbortSignals.push(options.signal);

if (this.#bulkPromise === undefined) {
this.#bulkPromise = this.#deferBatchedGet();
Expand All @@ -68,8 +71,10 @@ export default class LatestTelemetryProvider {

return openMctStyleDatum;
} catch (error) {
console.error(error);
this.#openmct.notifications.error(`Unable to fetch latest telemetry for ${domainObject.name}`);
if (error.name !== 'AbortError') {
console.error(error);
this.#openmct.notifications.error(`Unable to fetch latest telemetry for ${domainObject.name}`);
}

return undefined;
}
Expand All @@ -79,14 +84,19 @@ export default class LatestTelemetryProvider {
// requests triggered in this iteration of the event loop

await this.#waitForDebounce();

let batchIds = [...new Set(this.#batchIds)];

// the number of signals could and probably will be different from deduped
// batchIds that's ok, we want to err on the side of caution
let signal = this.#getMultiAbortSignal(this.#batchAbortSignals);

this.#clearBatch();

return this.#bulkGet(batchIds);
return this.#bulkGet(batchIds, signal);

}
async #bulkGet(batchIds) {
async #bulkGet(batchIds, signal) {
const yamcsIds = batchIds.map((yamcsId) => {
return {
name: yamcsId
Expand All @@ -100,7 +110,8 @@ export default class LatestTelemetryProvider {

const response = await fetch(this.#buildUrl(), {
method: 'POST',
body: JSON.stringify(requestBody)
body: JSON.stringify(requestBody),
signal
});

const json = await response.json();
Expand All @@ -118,6 +129,7 @@ export default class LatestTelemetryProvider {

#clearBatch() {
this.#batchIds = [];
this.#batchAbortSignals = [];
this.#bulkPromise = undefined;
}

Expand All @@ -131,7 +143,21 @@ export default class LatestTelemetryProvider {
}, BATCH_DEBOUNCE_MS);
});
}
#getMultiAbortSignal(signals) {
const controller = new AbortController();
let abortedCount = 0;

signals.forEach(signal => {
signal.addEventListener('abort', () => {
abortedCount++;
if (abortedCount === signals.length) {
controller.abort();
}
});
});

return controller.signal;
}
#buildUrl() {
let url = `${this.url}api/processors/${this.instance}/${this.processor}/parameters:batchGet`;

Expand Down
4 changes: 2 additions & 2 deletions src/providers/staleness-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export default class YamcsStalenessProvider {
return this.realtimeTelemetryProvider.subscribeToStaleness(domainObject, callback);
}

async isStale(domainObject) {
const response = await this.latestTelemetryProvider.requestLatest(domainObject);
async isStale(domainObject, options) {
const response = await this.latestTelemetryProvider.requestLatest(domainObject, options);

if (!response?.acquisitionStatus) {
return;
Expand Down
Loading