From d4bbd9ebefd8121673ce908b71bd226733103d3d Mon Sep 17 00:00:00 2001 From: Ben Wilson Date: Fri, 4 Aug 2023 16:40:52 -0400 Subject: [PATCH] client cleanup --- src/ORM/client/client.service.ts | 20 ++++++++++---------- src/services/app.service.ts | 12 ++++++------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/ORM/client/client.service.ts b/src/ORM/client/client.service.ts index 1d7dd88..b8cf974 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 { Repository } from 'typeorm'; +import { IsNull, LessThan, Repository } from 'typeorm'; import { ClientEntity } from './client.entity'; @@ -17,16 +17,16 @@ export class ClientService { } - // public async killDeadClients(){ - // var tenMinutes = new Date(new Date().getTime() - (60 * 60 * 1000)); + public async killDeadClients() { + var tenMinutes = new Date(new Date().getTime() - (60 * 60 * 1000)); - // return await this.clientRepository.update({ - // deletedAt: IsNull(), - // updatedAt: LessThan(tenMinutes) - // }, { - // deletedAt: new Date() - // }); - // } + return await this.clientRepository.update({ + deletedAt: IsNull(), + updatedAt: LessThan(tenMinutes) + }, { + deletedAt: new Date() + }); + } public async heartbeat(address: string, clientName: string, sessionId: string) { return await this.clientRepository.update({ address, clientName, sessionId }, { deletedAt: null, updatedAt: new Date() }); diff --git a/src/services/app.service.ts b/src/services/app.service.ts index 7bed703..1ba4a3c 100644 --- a/src/services/app.service.ts +++ b/src/services/app.service.ts @@ -36,11 +36,11 @@ export class AppService implements OnModuleInit { } } - // @Cron(CronExpression.EVERY_10_MINUTES) - // private async killDeadClients() { + @Cron(CronExpression.EVERY_10_MINUTES) + private async killDeadClients() { - // if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') { - // 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