Cluster rollback
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2022-11-04 11:27:20 +01:00
parent f5d24b9a9e
commit 4d2003c714
1 changed files with 33 additions and 24 deletions

View File

@ -2,7 +2,7 @@ const fs = require('fs');
const path = require('path');
const config = require('./config');
const Component = require('./component');
const Cluster = require('./cluster');
const puppeteer = require('puppeteer');
if (!process.env.OPENSSL_CONF)
process.env.OPENSSL_CONF = '/etc/ssl/';
@ -32,30 +32,39 @@ class Report extends Component {
if (fs.existsSync(fullPath))
options = require(optionsPath);
return new Promise(resolve => {
Cluster.pool.queue({}, async({page}) => {
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 stream = await page.pdf(options);
resolve(stream);
});
const browser = await puppeteer.launch({
headless: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--single-process',
'--no-zygote'
]
});
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;
}
/**