diff --git a/src/ORM/client/client.service.ts b/src/ORM/client/client.service.ts index 768ed6b..cffbb04 100644 --- a/src/ORM/client/client.service.ts +++ b/src/ORM/client/client.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { IsNull, LessThan, Repository } from 'typeorm'; +import { Repository } from 'typeorm'; import { ClientEntity } from './client.entity'; @@ -20,14 +20,14 @@ export class ClientService { public async killDeadClients() { - var tenMinutes = new Date(new Date().getTime() - (10 * 60 * 1000)); + var tenMinutes = new Date(new Date().getTime() - (10 * 60 * 1000)).toISOString(); - return await this.clientRepository.update({ - deletedAt: IsNull(), - updatedAt: LessThan(tenMinutes) - }, { - deletedAt: new Date() - }); + return await this.clientRepository + .createQueryBuilder() + .update(ClientEntity) + .set({ deletedAt: () => "DATETIME('now')" }) + .where("deletedAt IS NULL AND updatedAt < :tenMinutes", { tenMinutes }) + .execute(); } public async heartbeat(address: string, clientName: string, sessionId: string) { diff --git a/src/services/app.service.ts b/src/services/app.service.ts index edc6211..a0e9a61 100644 --- a/src/services/app.service.ts +++ b/src/services/app.service.ts @@ -38,6 +38,9 @@ export class AppService implements OnModuleInit { @Cron(CronExpression.EVERY_10_MINUTES) private async killDeadClients() { - await this.clientService.killDeadClients(); + + if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') { + await this.clientService.killDeadClients(); + } } } \ No newline at end of file