Skip to content

Commit

Permalink
feat(nxapi): Decrease TELEX API poll rate to random number 45-75. (fl…
Browse files Browse the repository at this point in the history
…ybywiresim#8303)

* Update NXApiConnector.ts

* Update CHANGELOG.md

* Update NXApiConnector.ts

---------

Co-authored-by: Aurora Luna Takemi <[email protected]>
  • Loading branch information
alepouna and alepouna authored Jan 8, 2024
1 parent 1f4922f commit 4230cce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
1. [EWD] Fixed PACKS indication when no FADECS - @ArtemisPlayer (ArtemisPlayer)
1. [FLIGHTMODEL/ICE PROT] - Interim fix for A/I system bug and quicker windscreen clearing of ice - @donstim (donbikes)
1. [ND] Worked around a font rendering bug with the ND chrono - @tracernz (Mike)
1. [TELEX] Decrease API poll rate to random number between 45-70 seconds - @auroraisluna (alepouna)

## 0.11.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,11 @@ export class NXApiConnector {
const retval: AtsuMessage[] = [];

if (NXApiConnector.connected) {
if (NXApiConnector.updateCounter++ % 4 === 0) {
const status = NXApiConnector.createAircraftStatus();
if (status !== undefined) {
const code = await Telex.update(status).then(() => AtsuStatusCodes.Ok).catch(() => AtsuStatusCodes.ProxyError);
if (code !== AtsuStatusCodes.Ok) {
return [AtsuStatusCodes.ComFailed, retval];
}
const status = NXApiConnector.createAircraftStatus();
if (status !== undefined) {
const code = await Telex.update(status).then(() => AtsuStatusCodes.Ok).catch(() => AtsuStatusCodes.ProxyError);
if (code !== AtsuStatusCodes.Ok) {
return [AtsuStatusCodes.ComFailed, retval];
}
}

Expand All @@ -217,7 +215,13 @@ export class NXApiConnector {
return [AtsuStatusCodes.Ok, retval];
}

/**
* Gets the interval to poll the NX API in milliseconds.
* Warning: This will return a different random time on each invocation!
* @returns The polling interval in milliseconds.
*/
public static pollInterval(): number {
return 15000;
// To relax the weight on API, we choose a random number between 45 and 75
return Math.random() * 30_000 + 45_000;
}
}

0 comments on commit 4230cce

Please sign in to comment.