Skip to content

Commit

Permalink
fix: clear UI server cache at simulator stop
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <[email protected]>
  • Loading branch information
Jérôme Benoit committed Feb 20, 2024
1 parent 88d3e6e commit 5c0e935
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/charging-station/Bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ export class Bootstrap extends EventEmitter {
await this.workerImplementation?.stop()
delete this.workerImplementation
this.removeAllListeners()
this.uiServer?.chargingStations.clear()
await this.storage?.close()
delete this.storage
this.started = false
Expand Down
11 changes: 7 additions & 4 deletions src/charging-station/ChargingStation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,7 @@ export class ChargingStation extends EventEmitter {

private async onOpen (): Promise<void> {
if (this.isWebSocketConnectionOpened()) {
this.emit(ChargingStationEvents.updated)
logger.info(
`${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.href} succeeded`
)
Expand Down Expand Up @@ -1894,6 +1895,7 @@ export class ChargingStation extends EventEmitter {

private onClose (code: WebSocketCloseEventStatusCode, reason: Buffer): void {
this.emit(ChargingStationEvents.disconnected)
this.emit(ChargingStationEvents.updated)
switch (code) {
// Normal close
case WebSocketCloseEventStatusCode.CLOSE_NORMAL:
Expand All @@ -1913,12 +1915,13 @@ export class ChargingStation extends EventEmitter {
)}' and reason '${reason.toString()}'`
)
this.started &&
this.reconnect().catch(error =>
logger.error(`${this.logPrefix()} Error while reconnecting:`, error)
)
this.reconnect()
.then(() => {
this.emit(ChargingStationEvents.updated)
})
.catch(error => logger.error(`${this.logPrefix()} Error while reconnecting:`, error))
break
}
this.emit(ChargingStationEvents.updated)
}

private getCachedRequest (
Expand Down
4 changes: 4 additions & 0 deletions src/charging-station/ui-server/AbstractUIServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export abstract class AbstractUIServer {
for (const uiService of this.uiServices.values()) {
uiService.stop()
}
this.clearCaches()
}

private clearCaches (): void {
this.chargingStations.clear()
this.chargingStationTemplates.clear()
}
Expand Down
12 changes: 11 additions & 1 deletion ui/web/src/views/ChargingStationsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
@click="loadChargingStations(() => $router.go(0))"
/>
</Container>
<CSTable :charging-stations="app?.appContext.config.globalProperties.$chargingStations" />
<CSTable
v-if="
Array.isArray(app?.appContext.config.globalProperties.$chargingStations) &&
app?.appContext.config.globalProperties.$chargingStations.length > 0
"
:charging-stations="app?.appContext.config.globalProperties.$chargingStations"
/>
</Container>
</template>

Expand Down Expand Up @@ -72,6 +78,9 @@ const stopSimulator = (): void => {
uiClient
.stopSimulator()
.then(() => {
if (app != null) {
app.appContext.config.globalProperties.$chargingStations = []
}
$toast.success('Simulator successfully stopped')
})
.catch((error: Error) => {
Expand All @@ -85,6 +94,7 @@ const stopSimulator = (): void => {
#charging-stations-container {
height: fit-content;
width: 100%;
position: absolute;
display: flex;
flex-direction: column;
}
Expand Down

0 comments on commit 5c0e935

Please sign in to comment.