mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
fixed killDeadClients
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { IsNull, LessThan, Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
|
||||||
import { ClientEntity } from './client.entity';
|
import { ClientEntity } from './client.entity';
|
||||||
|
|
||||||
@@ -20,14 +20,14 @@ export class ClientService {
|
|||||||
|
|
||||||
|
|
||||||
public async killDeadClients() {
|
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({
|
return await this.clientRepository
|
||||||
deletedAt: IsNull(),
|
.createQueryBuilder()
|
||||||
updatedAt: LessThan(tenMinutes)
|
.update(ClientEntity)
|
||||||
}, {
|
.set({ deletedAt: () => "DATETIME('now')" })
|
||||||
deletedAt: new Date()
|
.where("deletedAt IS NULL AND updatedAt < :tenMinutes", { tenMinutes })
|
||||||
});
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async heartbeat(address: string, clientName: string, sessionId: string) {
|
public async heartbeat(address: string, clientName: string, sessionId: string) {
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ export class AppService implements OnModuleInit {
|
|||||||
|
|
||||||
@Cron(CronExpression.EVERY_10_MINUTES)
|
@Cron(CronExpression.EVERY_10_MINUTES)
|
||||||
private async killDeadClients() {
|
private async killDeadClients() {
|
||||||
|
|
||||||
|
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
|
||||||
await this.clientService.killDeadClients();
|
await this.clientService.killDeadClients();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user