Parellized the chunks

ref #5
This commit is contained in:
Nicolai Ort 2021-02-07 16:28:26 +01:00
parent 4773a5f18c
commit e92820e12f
1 changed files with 9 additions and 4 deletions

View File

@ -54,24 +54,29 @@ export class PdfCreator {
* @param runner The runner you want to generate the contracts for.
* @param locale The locale used for the contracts (default:en)
*/
public async generateSponsoringContract(runners: Runner[], locale: string = "en"): Promise<any> {
public async generateSponsoringContract(runners: Runner[], locale: string = "en"): Promise<Buffer> {
if (runners.length == 1 && Object.keys(runners[0]).length == 0) {
runners[0] = this.generateEmptyRunner();
}
if (runners.length > 100) {
let pdfs: Buffer[] = new Array<Buffer>();
let pdf_promises = new Array<Promise<Buffer>>();
let i, j;
for (i = 0, j = runners.length; i < j; i += 100) {
let chunk = runners.slice(i, i + 100);
pdfs.push(await this.generateSponsoringContract(chunk, locale));
pdf_promises.push(this.generateSponsoringContract(chunk, locale));
}
const pdfs = await Promise.all(pdf_promises);
return await this.mergePdfs(pdfs);
}
console.log("triggered")
await i18next.changeLanguage(locale);
const template_source = fs.readFileSync(`${this.templateDir}/sponsoring_contract.html`, 'utf8');
const template = Handlebars.compile(template_source);
const result = template({ runners })
return await this.renderPdf(result, { format: "A5", landscape: true });
console.log("finished: bars")
const pdf = await this.renderPdf(result, { format: "A5", landscape: true });
console.log("finished: puppet")
return pdf
}
/**