Init
This commit is contained in:
26
backend/src/support/heapdump/heapdump.service.ts
Normal file
26
backend/src/support/heapdump/heapdump.service.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
import { DateUtil } from '@/common';
|
||||
|
||||
import { SupportConfig } from '../config';
|
||||
|
||||
@Injectable()
|
||||
export class HeapdumpService {
|
||||
private readonly _config: SupportConfig | undefined;
|
||||
|
||||
constructor(private readonly configService: ConfigService) {
|
||||
this._config = this.configService.get<SupportConfig>('support');
|
||||
}
|
||||
|
||||
public async writeSnapshot(code: string) {
|
||||
if (this._config?.accessCode && this._config.accessCode === code) {
|
||||
try {
|
||||
const { writeSnapshot } = await import('heapdump');
|
||||
writeSnapshot(`heapdump-${DateUtil.now().toISOString()}.heapsnapshot`);
|
||||
} catch (error) {
|
||||
console.error('Heapdump not available:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user