我们已经创建了一个生成PDF的Cloud Function。我们正在使用的库是
https://www.npmjs.com/package/html-pdf
问题是当我们尝试执行]时>
.create()
方法超时并出现以下错误
"Error: html-pdf: PDF generation timeout. Phantom.js script did not exit. at Timeout.execTimeout (/srv/node_modules/html-pdf/lib/pdf.js:91:19) at ontimeout (timers.js:498:11)
这在localhost上工作正常,但是在我们在GCP上部署该功能时会发生。
我们已经尝试过的一些解决方案:
解决方案1
是的,我们已将超时设置更新为const options = { format: "A3", orientation: "portrait", timeout: "100000" // zoomFactor: "0.5" // orientation: "portrait" };
并且它仍然不起作用。
这是触发PDF功能的最后一个片段
const options = {
format: "A3",
orientation: "portrait",
timeout: "100000"
// zoomFactor: "0.5"
// orientation: "portrait"
};
try {
// let pdfRes = await new Promise(async (resolve, reject) => {
console.log("Before pdf.create()")
let pdfResponse = await pdf.create(html, options).toFile(localPDFFile, async function (err, res) {
if (err) {
console.log(err)
}
console.log('response of pdf.create(): ', res);
let uploadBucket = await bucket.upload(localPDFFile, {
metadata: { contentType: "application/octet-stream" }
});
let docRef = await db
.collection("Organizations")
.doc(context.params.orgId)
.collection("regulations")
.doc(context.params.regulationId)
.collection("reports")
.doc(context.params.reportId);
await docRef.update({
pdf: {
status: "created",
reportName: pdfName
}
});
});
} catch (error) {
console.log('error: ', error);
}
``
我们已经创建了一个生成PDF的Cloud Function。我们正在使用的库是https://www.npmjs.com/package/html-pdf问题是当我们尝试执行.create()方法时,它的次数是...
即使在我当前的项目中,我也看到过许多类似的情况,我们使用了阶跃函数(当云函数需要更多的计算能力时,我们将其划分为大块),但是我认为阶跃函数在您的情况下将不起作用。根据您的情况,应使用计算引擎执行此操作。