2023-03-03 16:23:46 +01:00
|
|
|
import { inject, injectable, injectAll } from "tsyringe";
|
|
|
|
|
Updated dependencies + A few other things (!150)
Initially this was going to be an update to dependencies but it seems i got a little carried away!
Anyways this PR removes 2 unused dependencies (`jshint` and `utf-8-validate`), and 2 other, `del` and `fs-extra` that were replaced by the built-in `fs/promises`.
It also renames all `tsconfig` and `Dockerfile` files, in a way that when viewed in a file tree sorted alphabetically they will be next to each other.
It also updates the typescript target to `ES2022`, and changes moduleResolution from `Node` to `Node10` (this isn't an update, they are the same thing but `Node` is now deprecated).
It also adds the `node:` discriminator to every import from built-in modules.
It also has major changes to the build script, `del` and `fs-extra` were only being used in the build script, it's now using `fs/promises` instead, cleaned up the code from some functions, adds better documentation to a few functions, and renames some gulp tasks and npm scripts to better represent what they actually do.
And finally it updates dependencies, except for `atomically` which can't be updated unless the project switches to ESM.
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/150
Co-authored-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com>
Co-committed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com>
2023-10-14 11:01:41 +02:00
|
|
|
import os from "node:os";
|
2023-03-03 16:23:46 +01:00
|
|
|
import { OnLoad } from "../di/OnLoad";
|
|
|
|
import { OnUpdate } from "../di/OnUpdate";
|
|
|
|
import { ILogger } from "../models/spt/utils/ILogger";
|
|
|
|
import { LocalisationService } from "../services/LocalisationService";
|
2023-10-10 13:03:20 +02:00
|
|
|
import { EncodingUtil } from "./EncodingUtil";
|
2023-03-03 16:23:46 +01:00
|
|
|
import { TimeUtil } from "./TimeUtil";
|
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export class App
|
|
|
|
{
|
|
|
|
protected onUpdateLastRun = {};
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
@inject("WinstonLogger") protected logger: ILogger,
|
|
|
|
@inject("TimeUtil") protected timeUtil: TimeUtil,
|
|
|
|
@inject("LocalisationService") protected localisationService: LocalisationService,
|
2023-10-10 13:03:20 +02:00
|
|
|
@inject("EncodingUtil") protected encodingUtil: EncodingUtil,
|
2023-03-03 16:23:46 +01:00
|
|
|
@injectAll("OnLoad") protected onLoadComponents: OnLoad[],
|
|
|
|
@injectAll("OnUpdate") protected onUpdateComponents: OnUpdate[]
|
|
|
|
)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
public async load(): Promise<void>
|
|
|
|
{
|
|
|
|
// execute onLoad callbacks
|
|
|
|
this.logger.info(this.localisationService.getText("executing_startup_callbacks"));
|
|
|
|
|
Updated dependencies + A few other things (!150)
Initially this was going to be an update to dependencies but it seems i got a little carried away!
Anyways this PR removes 2 unused dependencies (`jshint` and `utf-8-validate`), and 2 other, `del` and `fs-extra` that were replaced by the built-in `fs/promises`.
It also renames all `tsconfig` and `Dockerfile` files, in a way that when viewed in a file tree sorted alphabetically they will be next to each other.
It also updates the typescript target to `ES2022`, and changes moduleResolution from `Node` to `Node10` (this isn't an update, they are the same thing but `Node` is now deprecated).
It also adds the `node:` discriminator to every import from built-in modules.
It also has major changes to the build script, `del` and `fs-extra` were only being used in the build script, it's now using `fs/promises` instead, cleaned up the code from some functions, adds better documentation to a few functions, and renames some gulp tasks and npm scripts to better represent what they actually do.
And finally it updates dependencies, except for `atomically` which can't be updated unless the project switches to ESM.
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/150
Co-authored-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com>
Co-committed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com>
2023-10-14 11:01:41 +02:00
|
|
|
this.logger.debug(`OS: ${os.arch()} | ${os.version()} | ${process.platform}`);
|
|
|
|
this.logger.debug(`CPU: ${os.cpus()[0]?.model} cores: ${os.cpus().length}`);
|
|
|
|
this.logger.debug(`RAM: ${(os.totalmem() / 1024 / 1024 / 1024).toFixed(2)}GB`);
|
2023-10-10 13:03:20 +02:00
|
|
|
this.logger.debug(`PATH: ${this.encodingUtil.toBase64(process.argv[0])}`);
|
|
|
|
this.logger.debug(`PATH: ${this.encodingUtil.toBase64(process.execPath)}`);
|
|
|
|
|
2023-03-03 16:23:46 +01:00
|
|
|
for (const onLoad of this.onLoadComponents)
|
|
|
|
{
|
|
|
|
await onLoad.onLoad();
|
|
|
|
}
|
|
|
|
|
|
|
|
setInterval(() =>
|
|
|
|
{
|
|
|
|
this.update(this.onUpdateComponents);
|
|
|
|
}, 5000);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected async update(onUpdateComponents: OnUpdate[]): Promise<void>
|
|
|
|
{
|
|
|
|
for (const updateable of onUpdateComponents)
|
|
|
|
{
|
|
|
|
let success = false;
|
|
|
|
const lastRunTimeTimestamp = this.onUpdateLastRun[updateable.getRoute()] || 0; // 0 on first load so all update() calls occur on first load
|
|
|
|
const secondsSinceLastRun = this.timeUtil.getTimestamp() - lastRunTimeTimestamp;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
success = await updateable.onUpdate(secondsSinceLastRun);
|
|
|
|
}
|
|
|
|
catch (err)
|
|
|
|
{
|
|
|
|
this.logUpdateException(err, updateable);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
{
|
|
|
|
this.onUpdateLastRun[updateable.getRoute()] = this.timeUtil.getTimestamp();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* temporary for debug */
|
|
|
|
const warnTime = 20 * 60;
|
|
|
|
|
|
|
|
if (success === void 0 && !(secondsSinceLastRun % warnTime))
|
|
|
|
{
|
|
|
|
this.logger.debug(this.localisationService.getText("route_onupdate_no_response", updateable.getRoute()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected logUpdateException(err: any, updateable: OnUpdate): void
|
|
|
|
{
|
|
|
|
this.logger.error(this.localisationService.getText("scheduled_event_failed_to_run", updateable.getRoute()));
|
|
|
|
if (err.message)
|
|
|
|
{
|
|
|
|
this.logger.error(err.message);
|
|
|
|
}
|
|
|
|
if (err.stack)
|
|
|
|
{
|
|
|
|
this.logger.error(err.stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|