forked from simrail/simrail.pro
fix(backend): main loop stops when simrail api is unresponsive
Signed-off-by: Aleksander Wilczyński <aleks@alekswilc.dev>
This commit is contained in:
parent
e0bee51d20
commit
efd51344f0
@ -66,7 +66,7 @@ export class SimrailClient extends EventEmitter
|
|||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
this.setup().then(() => {
|
this.setup().then(() => {
|
||||||
void this.update();
|
void this.update(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -277,7 +277,7 @@ export class SimrailClient extends EventEmitter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async update()
|
private async update(needSetup: boolean = false)
|
||||||
{
|
{
|
||||||
const servers = (await fetch("https://panel.simrail.eu:8084/servers-open").then(x => x.json()).catch(() => ({ data: [], result: false })) as ApiResponse<Server>)
|
const servers = (await fetch("https://panel.simrail.eu:8084/servers-open").then(x => x.json()).catch(() => ({ data: [], result: false })) as ApiResponse<Server>)
|
||||||
.data ?? [] //?.filter(x => x.ServerName.includes("Polski")) ?? []; // TODO: remove this in v3
|
.data ?? [] //?.filter(x => x.ServerName.includes("Polski")) ?? []; // TODO: remove this in v3
|
||||||
@ -285,9 +285,16 @@ export class SimrailClient extends EventEmitter
|
|||||||
if (!servers.length)
|
if (!servers.length)
|
||||||
{
|
{
|
||||||
console.log("SimrailAPI is down");
|
console.log("SimrailAPI is down");
|
||||||
|
await new Promise(res => setTimeout(res, 5000));
|
||||||
|
await this.update(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (needSetup)
|
||||||
|
{
|
||||||
|
await this.setup();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: maybe node:worker_threads?
|
// TODO: maybe node:worker_threads?
|
||||||
// TODO: check performance
|
// TODO: check performance
|
||||||
for (const server of servers)
|
for (const server of servers)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user