LLS: rename wireError (#8401)
* rename wireError in ownbeaconstore to locationPublishError Signed-off-by: Kerry Archibald <kerrya@element.io> * rename getLiveBeaconIdsWithWireError -> getLiveBeaconIdsWithLocationPublishError Signed-off-by: Kerry Archibald <kerrya@element.io> * rename wire error variables in components Signed-off-by: Kerry Archibald <kerrya@element.io> * new snapshots for new test names Signed-off-by: Kerry Archibald <kerrya@element.io> * fix bad capitalisation on onResetLocationPublishError Signed-off-by: Kerry Archibald <kerrya@element.io> * missed variable Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
parent
a3f9123f6c
commit
8c6786bad6
11 changed files with 133 additions and 120 deletions
|
@ -50,7 +50,7 @@ const isOwnBeacon = (beacon: Beacon, userId: string): boolean => beacon.beaconIn
|
|||
export enum OwnBeaconStoreEvent {
|
||||
LivenessChange = 'OwnBeaconStore.LivenessChange',
|
||||
MonitoringLivePosition = 'OwnBeaconStore.MonitoringLivePosition',
|
||||
WireError = 'WireError',
|
||||
LocationPublishError = 'LocationPublishError',
|
||||
}
|
||||
|
||||
const MOVING_UPDATE_INTERVAL = 2000;
|
||||
|
@ -60,7 +60,7 @@ const BAIL_AFTER_CONSECUTIVE_ERROR_COUNT = 2;
|
|||
|
||||
type OwnBeaconStoreState = {
|
||||
beacons: Map<BeaconIdentifier, Beacon>;
|
||||
beaconWireErrors: Map<string, Beacon>;
|
||||
beaconLocationPublishErrorCounts: Map<BeaconIdentifier, number>;
|
||||
beaconsByRoomId: Map<Room['roomId'], Set<BeaconIdentifier>>;
|
||||
liveBeaconIds: BeaconIdentifier[];
|
||||
};
|
||||
|
@ -98,7 +98,7 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
|
|||
* Counts consecutive wire errors per beacon
|
||||
* Reset on successful publish of location
|
||||
*/
|
||||
public readonly beaconWireErrorCounts = new Map<BeaconIdentifier, number>();
|
||||
public readonly beaconLocationPublishErrorCounts = new Map<BeaconIdentifier, number>();
|
||||
/**
|
||||
* ids of live beacons
|
||||
* ordered by creation time descending
|
||||
|
@ -143,7 +143,7 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
|
|||
this.beacons.clear();
|
||||
this.beaconsByRoomId.clear();
|
||||
this.liveBeaconIds = [];
|
||||
this.beaconWireErrorCounts.clear();
|
||||
this.beaconLocationPublishErrorCounts.clear();
|
||||
}
|
||||
|
||||
protected async onReady(): Promise<void> {
|
||||
|
@ -168,8 +168,8 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
|
|||
* Some live beacon has a wire error
|
||||
* Optionally filter by room
|
||||
*/
|
||||
public hasWireErrors = (roomId?: string): boolean => {
|
||||
return this.getLiveBeaconIds(roomId).some(this.beaconHasWireError);
|
||||
public hasLocationPublishErrors = (roomId?: string): boolean => {
|
||||
return this.getLiveBeaconIds(roomId).some(this.beaconHasLocationPublishError);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -177,12 +177,12 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
|
|||
* past the allowed consecutive failure count (BAIL_AFTER_CONSECUTIVE_ERROR_COUNT)
|
||||
* Then consider it to have an error
|
||||
*/
|
||||
public beaconHasWireError = (beaconId: string): boolean => {
|
||||
return this.beaconWireErrorCounts.get(beaconId) >= BAIL_AFTER_CONSECUTIVE_ERROR_COUNT;
|
||||
public beaconHasLocationPublishError = (beaconId: string): boolean => {
|
||||
return this.beaconLocationPublishErrorCounts.get(beaconId) >= BAIL_AFTER_CONSECUTIVE_ERROR_COUNT;
|
||||
};
|
||||
|
||||
public resetWireError = (beaconId: string): void => {
|
||||
this.incrementBeaconWireErrorCount(beaconId, false);
|
||||
public resetLocationPublishError = (beaconId: string): void => {
|
||||
this.incrementBeaconLocationPublishErrorCount(beaconId, false);
|
||||
|
||||
// always publish to all live beacons together
|
||||
// instead of just one that was changed
|
||||
|
@ -198,8 +198,8 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
|
|||
return this.liveBeaconIds.filter(beaconId => this.beaconsByRoomId.get(roomId)?.has(beaconId));
|
||||
};
|
||||
|
||||
public getLiveBeaconIdsWithWireError = (roomId?: string): string[] => {
|
||||
return this.getLiveBeaconIds(roomId).filter(this.beaconHasWireError);
|
||||
public getLiveBeaconIdsWithLocationPublishError = (roomId?: string): string[] => {
|
||||
return this.getLiveBeaconIds(roomId).filter(this.beaconHasLocationPublishError);
|
||||
};
|
||||
|
||||
public getBeaconById = (beaconId: string): Beacon | undefined => {
|
||||
|
@ -300,7 +300,7 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
|
|||
* Live beacon ids that do not have wire errors
|
||||
*/
|
||||
private get healthyLiveBeaconIds() {
|
||||
return this.liveBeaconIds.filter(beaconId => !this.beaconHasWireError(beaconId));
|
||||
return this.liveBeaconIds.filter(beaconId => !this.beaconHasLocationPublishError(beaconId));
|
||||
}
|
||||
|
||||
private initialiseBeaconState = () => {
|
||||
|
@ -546,10 +546,10 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
|
|||
const content = makeBeaconContent(geoUri, timestamp, beacon.beaconInfoId);
|
||||
try {
|
||||
await this.matrixClient.sendEvent(beacon.roomId, M_BEACON.name, content);
|
||||
this.incrementBeaconWireErrorCount(beacon.identifier, false);
|
||||
this.incrementBeaconLocationPublishErrorCount(beacon.identifier, false);
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
this.incrementBeaconWireErrorCount(beacon.identifier, true);
|
||||
this.incrementBeaconLocationPublishErrorCount(beacon.identifier, true);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -559,22 +559,22 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
|
|||
* - increment count for beacon when is error
|
||||
* - emit if beacon error count crossed threshold
|
||||
*/
|
||||
private incrementBeaconWireErrorCount = (beaconId: string, isError: boolean): void => {
|
||||
const hadError = this.beaconHasWireError(beaconId);
|
||||
private incrementBeaconLocationPublishErrorCount = (beaconId: string, isError: boolean): void => {
|
||||
const hadError = this.beaconHasLocationPublishError(beaconId);
|
||||
|
||||
if (isError) {
|
||||
// increment error count
|
||||
this.beaconWireErrorCounts.set(
|
||||
this.beaconLocationPublishErrorCounts.set(
|
||||
beaconId,
|
||||
(this.beaconWireErrorCounts.get(beaconId) ?? 0) + 1,
|
||||
(this.beaconLocationPublishErrorCounts.get(beaconId) ?? 0) + 1,
|
||||
);
|
||||
} else {
|
||||
// clear any error count
|
||||
this.beaconWireErrorCounts.delete(beaconId);
|
||||
this.beaconLocationPublishErrorCounts.delete(beaconId);
|
||||
}
|
||||
|
||||
if (this.beaconHasWireError(beaconId) !== hadError) {
|
||||
this.emit(OwnBeaconStoreEvent.WireError, beaconId);
|
||||
if (this.beaconHasLocationPublishError(beaconId) !== hadError) {
|
||||
this.emit(OwnBeaconStoreEvent.LocationPublishError, beaconId);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue