fixes #5529 Fixes: missing awaits, buffer-to-file
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
e8f0a49f0c
commit
0372d44415
|
@ -56,7 +56,7 @@ module.exports = Self => {
|
||||||
reference: invoiceOut.ref,
|
reference: invoiceOut.ref,
|
||||||
recipientId: invoiceOut.clientFk
|
recipientId: invoiceOut.clientFk
|
||||||
});
|
});
|
||||||
const stream = await invoiceReport.toPdfStream();
|
const buffer = await invoiceReport.toPdfStream();
|
||||||
|
|
||||||
const issued = invoiceOut.issued;
|
const issued = invoiceOut.issued;
|
||||||
const year = issued.getFullYear().toString();
|
const year = issued.getFullYear().toString();
|
||||||
|
@ -66,7 +66,7 @@ module.exports = Self => {
|
||||||
const fileName = `${year}${invoiceOut.ref}.pdf`;
|
const fileName = `${year}${invoiceOut.ref}.pdf`;
|
||||||
|
|
||||||
// Store invoice
|
// Store invoice
|
||||||
print.storage.write(stream, {
|
await print.storage.write(buffer, {
|
||||||
type: 'invoice',
|
type: 'invoice',
|
||||||
path: `${year}/${month}/${day}`,
|
path: `${year}/${month}/${day}`,
|
||||||
fileName: fileName
|
fileName: fileName
|
||||||
|
|
|
@ -100,16 +100,23 @@ class Controller extends Section {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$http.post(`InvoiceOuts/invoiceClient`, params)
|
this.$http.post(`InvoiceOuts/invoiceClient`, params)
|
||||||
|
.then(() => this.invoiceNext())
|
||||||
.catch(res => {
|
.catch(res => {
|
||||||
this.errors.unshift({
|
const message = res.data?.error?.message || res.message;
|
||||||
address,
|
if (res.status >= 400 && res.status < 500) {
|
||||||
message: res.data.error.message
|
this.errors.unshift({address, message});
|
||||||
});
|
this.invoiceNext();
|
||||||
|
} else {
|
||||||
|
this.invoicing = false;
|
||||||
|
this.status = 'done';
|
||||||
|
throw new UserError(`Critical invoicing error, proccess stopped`);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.finally(() => {
|
}
|
||||||
|
|
||||||
|
invoiceNext() {
|
||||||
this.addressIndex++;
|
this.addressIndex++;
|
||||||
this.invoiceOut();
|
this.invoiceOut();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get nAddresses() {
|
get nAddresses() {
|
||||||
|
|
|
@ -18,3 +18,4 @@ Invoice out: Facturar
|
||||||
One client: Un solo cliente
|
One client: Un solo cliente
|
||||||
Choose a valid client: Selecciona un cliente válido
|
Choose a valid client: Selecciona un cliente válido
|
||||||
Stop: Parar
|
Stop: Parar
|
||||||
|
Critical invoicing error, proccess stopped: Error crítico al facturar, proceso detenido
|
|
@ -46,7 +46,7 @@ module.exports = async function(Self, tickets, reqArgs = {}) {
|
||||||
const fileName = `${year}${invoiceOut.ref}.pdf`;
|
const fileName = `${year}${invoiceOut.ref}.pdf`;
|
||||||
|
|
||||||
// Store invoice
|
// Store invoice
|
||||||
storage.write(stream, {
|
await storage.write(stream, {
|
||||||
type: 'invoice',
|
type: 'invoice',
|
||||||
path: `${year}/${month}/${day}`,
|
path: `${year}/${month}/${day}`,
|
||||||
fileName: fileName
|
fileName: fileName
|
||||||
|
|
|
@ -4,7 +4,7 @@ const {cpus} = require('os');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init() {
|
init() {
|
||||||
if (!this.pool) {
|
if (this.pool) return;
|
||||||
Cluster.launch({
|
Cluster.launch({
|
||||||
concurrency: Cluster.CONCURRENCY_CONTEXT,
|
concurrency: Cluster.CONCURRENCY_CONTEXT,
|
||||||
maxConcurrency: cpus().length,
|
maxConcurrency: cpus().length,
|
||||||
|
@ -16,8 +16,7 @@ module.exports = {
|
||||||
'--no-zygote'
|
'--no-zygote'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
})
|
}).then(cluster => {
|
||||||
.then(cluster => {
|
|
||||||
this.pool = cluster;
|
this.pool = cluster;
|
||||||
|
|
||||||
log4js.configure({
|
log4js.configure({
|
||||||
|
@ -39,5 +38,4 @@ module.exports = {
|
||||||
cluster.on('queue', () => logger.info('Printing task initialized by pool'));
|
cluster.on('queue', () => logger.info('Printing task initialized by pool'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -32,8 +32,9 @@ class Report extends Component {
|
||||||
if (fs.existsSync(fullPath))
|
if (fs.existsSync(fullPath))
|
||||||
options = require(optionsPath);
|
options = require(optionsPath);
|
||||||
|
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve, reject) => {
|
||||||
Cluster.pool.queue({}, async({page}) => {
|
Cluster.pool.queue({}, async({page}) => {
|
||||||
|
try {
|
||||||
await page.emulateMediaType('screen');
|
await page.emulateMediaType('screen');
|
||||||
await page.setContent(template);
|
await page.setContent(template);
|
||||||
|
|
||||||
|
@ -51,9 +52,11 @@ class Report extends Component {
|
||||||
options.headerTemplate = '\n';
|
options.headerTemplate = '\n';
|
||||||
options.footerTemplate = footer;
|
options.footerTemplate = footer;
|
||||||
|
|
||||||
const stream = await page.pdf(options);
|
const buffer = await page.pdf(options);
|
||||||
|
resolve(buffer);
|
||||||
resolve(stream);
|
} catch (err) {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,26 +3,14 @@ const path = require('path');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
async write(stream, options) {
|
async write(buffer, options) {
|
||||||
const storage = config.storage[options.type];
|
const storage = config.storage[options.type];
|
||||||
|
|
||||||
if (!storage) return;
|
if (!storage) return;
|
||||||
|
|
||||||
const src = path.join(storage.root, options.path);
|
const src = path.join(storage.root, options.path);
|
||||||
const fileSrc = path.join(src, options.fileName);
|
const fileSrc = path.join(src, options.fileName);
|
||||||
|
|
||||||
await fs.mkdir(src, {recursive: true});
|
await fs.mkdir(src, {recursive: true});
|
||||||
|
await fs.writeFile(fileSrc, buffer);
|
||||||
const writeStream = fs.createWriteStream(fileSrc);
|
|
||||||
writeStream.on('open', () => writeStream.write(stream));
|
|
||||||
writeStream.on('finish', () => writeStream.end());
|
|
||||||
|
|
||||||
return new Promise(resolve => {
|
|
||||||
writeStream.on('close', () => resolve());
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
load(type, data) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue