statistics bug

This commit is contained in:
Ben Wilson
2023-08-02 09:36:19 -04:00
parent 0f62fb1de1
commit 978fc7cd1a
4 changed files with 84 additions and 73 deletions
@@ -38,7 +38,7 @@ export class ClientStatisticsService {
.createQueryBuilder() .createQueryBuilder()
.delete() .delete()
.from(ClientStatisticsEntity) .from(ClientStatisticsEntity)
.where('time < :time', { time: oneDayAgo }) .where('time < :time', { time: oneDayAgo.getTime() })
.execute(); .execute();
} }
+1 -1
View File
@@ -33,7 +33,7 @@ export class ClientService {
.createQueryBuilder() .createQueryBuilder()
.delete() .delete()
.from(ClientEntity) .from(ClientEntity)
.where('deletedAt < :time', { time: oneDayAgo }) .where('deletedAt < :deletedAt', { deletedAt: oneDayAgo })
.execute(); .execute();
} }
+2
View File
@@ -19,9 +19,11 @@ export class CleanupService implements OnModuleInit {
@Cron(CronExpression.EVERY_HOUR) @Cron(CronExpression.EVERY_HOUR)
private async deleteOldStatistics() { private async deleteOldStatistics() {
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
const deletedStatistics = await this.clientStatisticsService.deleteOldStatistics(); const deletedStatistics = await this.clientStatisticsService.deleteOldStatistics();
console.log(`Deleted ${deletedStatistics.affected} old statistics`); console.log(`Deleted ${deletedStatistics.affected} old statistics`);
const deletedClients = await this.clientService.deleteOldClients(); const deletedClients = await this.clientService.deleteOldClients();
console.log(`Deleted ${deletedClients.affected} old clients`); console.log(`Deleted ${deletedClients.affected} old clients`);
} }
}
} }
+11 -2
View File
@@ -34,6 +34,7 @@ export class DiscordService implements OnModuleInit {
constructor(private readonly configService: ConfigService) { constructor(private readonly configService: ConfigService) {
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
this.token = this.configService.get('DISCORD_BOT_TOKEN'); this.token = this.configService.get('DISCORD_BOT_TOKEN');
this.clientId = this.configService.get('DISCORD_BOT_CLIENTID'); this.clientId = this.configService.get('DISCORD_BOT_CLIENTID');
this.guildId = this.configService.get('DISCORD_BOT_GUILD_ID'); this.guildId = this.configService.get('DISCORD_BOT_GUILD_ID');
@@ -56,16 +57,17 @@ export class DiscordService implements OnModuleInit {
this.bot = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] }); this.bot = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
this.bot.login(this.token); this.bot.login(this.token);
} }
}
async onModuleInit(): Promise<void> { async onModuleInit(): Promise<void> {
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
if (this.bot == null) { if (this.bot == null) {
return; return;
} }
await this.registerCommands(); await this.registerCommands();
this.bot.on(Events.InteractionCreate, async interaction => { this.bot.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return; if (!interaction.isChatInputCommand()) return;
@@ -88,8 +90,10 @@ export class DiscordService implements OnModuleInit {
} }
}); });
} }
}
private async registerCommands() { private async registerCommands() {
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
const rest = new REST().setToken(this.token); const rest = new REST().setToken(this.token);
try { try {
console.log(`Started refreshing ${commands.length} application (/) commands.`); console.log(`Started refreshing ${commands.length} application (/) commands.`);
@@ -106,8 +110,10 @@ export class DiscordService implements OnModuleInit {
console.error(error); console.error(error);
} }
} }
}
public async notifyRestarted() { public async notifyRestarted() {
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
if (this.bot == null) { if (this.bot == null) {
return; return;
} }
@@ -116,14 +122,17 @@ export class DiscordService implements OnModuleInit {
const channel = await guild.channels.fetch(this.channelId) as TextChannel; const channel = await guild.channels.fetch(this.channelId) as TextChannel;
channel.send(`Server Restarted.`); channel.send(`Server Restarted.`);
} }
}
public async notifySubscribersBlockFound(height: number, block: Block, message: string) { public async notifySubscribersBlockFound(height: number, block: Block, message: string) {
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
if (this.bot == null) { if (this.bot == null) {
return; return;
} }
const guild = await this.bot.guilds.fetch(this.guildId); const guild = await this.bot.guilds.fetch(this.guildId);
const channel = await guild.channels.fetch(this.channelId) as TextChannel; const channel = await guild.channels.fetch(this.channelId) as TextChannel;
channel.send(`Block Found! Result: ${message}, Height: ${height}`) channel.send(`Block Found! Result: ${message}, Height: ${height}`);
}
} }
} }