Enabled puppeteer cluster
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2022-11-04 12:52:25 +01:00
parent 104eea2e4f
commit 785e7aa9fa
1 changed files with 24 additions and 33 deletions

View File

@ -2,7 +2,7 @@ const fs = require('fs');
const path = require('path'); const path = require('path');
const config = require('./config'); const config = require('./config');
const Component = require('./component'); const Component = require('./component');
const puppeteer = require('puppeteer'); const Cluster = require('./cluster');
if (!process.env.OPENSSL_CONF) if (!process.env.OPENSSL_CONF)
process.env.OPENSSL_CONF = '/etc/ssl/'; process.env.OPENSSL_CONF = '/etc/ssl/';
@ -32,17 +32,8 @@ class Report extends Component {
if (fs.existsSync(fullPath)) if (fs.existsSync(fullPath))
options = require(optionsPath); options = require(optionsPath);
const browser = await puppeteer.launch({ return new Promise(resolve => {
headless: true, Cluster.pool.queue({}, async({page}) => {
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--single-process',
'--no-zygote'
]
});
const page = (await browser.pages())[0];
await page.emulateMediaType('screen'); await page.emulateMediaType('screen');
await page.setContent(template); await page.setContent(template);
@ -60,11 +51,11 @@ class Report extends Component {
options.headerTemplate = '\n'; options.headerTemplate = '\n';
options.footerTemplate = footer; options.footerTemplate = footer;
const buffer = await page.pdf(options); const stream = await page.pdf(options);
await browser.close(); resolve(stream);
});
return buffer; });
} }
/** /**