Skip to content

Commit

Permalink
fix: Release memory on report generation (#1669)
Browse files Browse the repository at this point in the history
  • Loading branch information
praju-aot authored Nov 21, 2024
1 parent c606867 commit 9045d4f
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions dops/src/modules/dgen/dgen.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { getFromCache } from '../../helper/cache.helper';
import * as Handlebars from 'handlebars';
import { CacheKey } from '../../enum/cache-key.enum';
import { CreateGeneratedReportDto } from './dto/request/create-generated-report.dto';
import puppeteer, { Browser } from 'puppeteer';
import puppeteer, { Browser, Page } from 'puppeteer';
import { IFile } from '../../interface/file.interface';
import { ReportTemplate } from '../../enum/report-template.enum';
import { convertUtcToPt } from '../../helper/date-time.helper';
Expand Down Expand Up @@ -221,20 +221,33 @@ export class DgenService {
};

let browser: Browser;
let page: Page;
try {
const browser = await puppeteer.launch({
browser = await puppeteer.launch({
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
'--disable-gpu',
'--disable-software-rasterizer',
'--disable-infobars',
'--disable-dev-shm-usage',
'--disable-web-security', // Use with caution
'--disable-sync',
'--disable-translate',
'--disable-popup-blocking',
'--disable-background-timer-throttling',
'--disable-backgrounding-occluded-windows',
'--disable-breakpad',
'--disable-client-side-phishing-detection',
'--disable-extensions',
'--disable-plugins',
],
pipe: true,
headless: true,
env: {
ELECTRON_DISABLE_SANDBOX: '1',
},
});
const page = await browser.newPage();
page = await browser.newPage();
await page.setContent(htmlBody);
await page.emulateMediaType('print');

Expand All @@ -255,6 +268,9 @@ export class DgenService {
this.logger.error(error);
throw error;
} finally {
if (page) {
await page.close();
}
if (browser) {
await browser.close();
}
Expand Down

0 comments on commit 9045d4f

Please sign in to comment.