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,39 +32,30 @@ 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: [ await page.emulateMediaType('screen');
'--no-sandbox', await page.setContent(template);
'--disable-setuid-sandbox',
'--single-process', const element = await page.$('#pageFooter');
'--no-zygote'
] let footer = '\n';
if (element) {
footer = await page.evaluate(el => {
const html = el.innerHTML;
el.remove();
return html;
}, element);
}
options.headerTemplate = '\n';
options.footerTemplate = footer;
const stream = await page.pdf(options);
resolve(stream);
});
}); });
const page = (await browser.pages())[0];
await page.emulateMediaType('screen');
await page.setContent(template);
const element = await page.$('#pageFooter');
let footer = '\n';
if (element) {
footer = await page.evaluate(el => {
const html = el.innerHTML;
el.remove();
return html;
}, element);
}
options.headerTemplate = '\n';
options.footerTemplate = footer;
const buffer = await page.pdf(options);
await browser.close();
return buffer;
} }
/** /**