refactor: introduce bindThis decorator to bind this automaticaly
This commit is contained in:
@@ -2,6 +2,7 @@ import { Inject, Injectable } from '@nestjs/common';
|
||||
import { LessThan } from 'typeorm';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import type { AttestationChallengesRepository } from '@/models/index.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import type { OnApplicationShutdown } from '@nestjs/common';
|
||||
|
||||
const interval = 30 * 60 * 1000;
|
||||
@@ -19,6 +20,7 @@ export class JanitorService implements OnApplicationShutdown {
|
||||
/**
|
||||
* Clean up database occasionally
|
||||
*/
|
||||
@bindThis
|
||||
public start(): void {
|
||||
const tick = async () => {
|
||||
await this.attestationChallengesRepository.delete({
|
||||
@@ -31,6 +33,7 @@ export class JanitorService implements OnApplicationShutdown {
|
||||
this.intervalId = setInterval(tick, interval);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public onApplicationShutdown(signal?: string | undefined) {
|
||||
clearInterval(this.intervalId);
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ import { Inject, Injectable } from '@nestjs/common';
|
||||
import Xev from 'xev';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { QueueService } from '@/core/QueueService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import type { OnApplicationShutdown } from '@nestjs/common';
|
||||
|
||||
const ev = new Xev();
|
||||
@@ -20,6 +21,7 @@ export class QueueStatsService implements OnApplicationShutdown {
|
||||
/**
|
||||
* Report queue stats regularly
|
||||
*/
|
||||
@bindThis
|
||||
public start(): void {
|
||||
const log = [] as any[];
|
||||
|
||||
@@ -71,6 +73,7 @@ export class QueueStatsService implements OnApplicationShutdown {
|
||||
this.intervalId = setInterval(tick, interval);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public onApplicationShutdown(signal?: string | undefined) {
|
||||
clearInterval(this.intervalId);
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ import si from 'systeminformation';
|
||||
import Xev from 'xev';
|
||||
import * as osUtils from 'os-utils';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import type { OnApplicationShutdown } from '@nestjs/common';
|
||||
|
||||
const ev = new Xev();
|
||||
@@ -23,6 +24,7 @@ export class ServerStatsService implements OnApplicationShutdown {
|
||||
/**
|
||||
* Report server stats regularly
|
||||
*/
|
||||
@bindThis
|
||||
public start(): void {
|
||||
const log = [] as any[];
|
||||
|
||||
@@ -61,6 +63,7 @@ export class ServerStatsService implements OnApplicationShutdown {
|
||||
this.intervalId = setInterval(tick, interval);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public onApplicationShutdown(signal?: string | undefined) {
|
||||
clearInterval(this.intervalId);
|
||||
}
|
||||
|
Reference in New Issue
Block a user