refs #4550 Fix: Cannot read property 'method' of undefined
gitea/printnatura/pipeline/head This commit looks good
Details
gitea/printnatura/pipeline/head This commit looks good
Details
This commit is contained in:
parent
00ea09c7e2
commit
d633fecae1
|
@ -73,15 +73,15 @@ class PrintServer {
|
|||
break;
|
||||
}
|
||||
}
|
||||
async reconnect() {
|
||||
async reconnect() {
|
||||
this.reconnectTimeout = null;
|
||||
try {
|
||||
try {
|
||||
await this.init();
|
||||
} catch (err) {
|
||||
this.reconnectTimeout = setTimeout(
|
||||
} catch (err) {
|
||||
this.reconnectTimeout = setTimeout(
|
||||
() => this.reconnect(), this.conf.reconnectTimeout * 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
async poll() {
|
||||
this.pollTimeout = null;
|
||||
try {
|
||||
|
@ -94,12 +94,13 @@ class PrintServer {
|
|||
async printJob() {
|
||||
const conn = this.conn;
|
||||
const conf = this.conf;
|
||||
let printJob;
|
||||
let jobId;
|
||||
let jobData;
|
||||
const args = {};
|
||||
|
||||
try {
|
||||
await conn.beginTransaction();
|
||||
[[printJob]] = await conn.query(selectQuery);
|
||||
const [[printJob]] = await conn.query(selectQuery);
|
||||
if (!printJob) {
|
||||
await conn.rollback();
|
||||
return;
|
||||
|
@ -107,6 +108,16 @@ class PrintServer {
|
|||
|
||||
jobId = printJob.id;
|
||||
|
||||
// Job data
|
||||
const [[data]] = await conn.query(jobDataQuery, jobId);
|
||||
jobData = data;
|
||||
|
||||
// Job arguments
|
||||
const args = {};
|
||||
const [res] = await conn.query(jobArgsQuery, jobId);
|
||||
for (const row of res)
|
||||
args[row.name] = row.value;
|
||||
|
||||
await conn.query(updateQuery, ['printing', null, jobId]);
|
||||
await conn.commit();
|
||||
} catch (err) {
|
||||
|
@ -115,14 +126,6 @@ class PrintServer {
|
|||
}
|
||||
|
||||
try {
|
||||
// Job data
|
||||
// FIXME: Cannot read property 'method' of undefined
|
||||
const [[jobData]] = await conn.query(jobDataQuery, jobId);
|
||||
const args = {};
|
||||
const [res] = await conn.query(jobArgsQuery, jobId);
|
||||
for (const row of res)
|
||||
args[row.name] = row.value;
|
||||
|
||||
// Path params
|
||||
const usedParams = new Set();
|
||||
const methodPath = jobData.method.replace(/{\w+}/g, function(match) {
|
||||
|
@ -135,10 +138,7 @@ class PrintServer {
|
|||
let pdfData;
|
||||
for (let attempts = 0; !pdfData && attempts < 2; attempts++) {
|
||||
// URL params
|
||||
const params = {
|
||||
access_token: this.token,
|
||||
userFk: printJob.userFk
|
||||
};
|
||||
const params = {userFk: jobData.userFk};
|
||||
for (const key in args) {
|
||||
if (!usedParams.has(key))
|
||||
params[key] = args[key];
|
||||
|
@ -152,7 +152,8 @@ class PrintServer {
|
|||
url: `${conf.salix.url}/api/${methodPath}?${urlParams.toString()}`,
|
||||
responseType: 'arraybuffer',
|
||||
headers: {
|
||||
'Accept': 'application/pdf'
|
||||
'Accept': 'application/pdf',
|
||||
'Authorization': this.token
|
||||
}
|
||||
});
|
||||
pdfData = response.data;
|
||||
|
@ -203,10 +204,10 @@ class PrintServer {
|
|||
module.exports = PrintServer;
|
||||
|
||||
function pExec(command) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
if (err) return reject(err);
|
||||
resolve({stdout, stderr})
|
||||
});
|
||||
});
|
||||
return new Promise(function(resolve, reject) {
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
if (err) return reject(err);
|
||||
resolve({stdout, stderr})
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
SELECT r.name report,
|
||||
SELECT pq.workerFk userFk,
|
||||
r.name report,
|
||||
p.name printer,
|
||||
r.method
|
||||
FROM printQueue pq
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
SELECT pq.id,
|
||||
pq.workerFk userFk
|
||||
SELECT pq.id
|
||||
FROM printQueue pq
|
||||
JOIN report r ON r.id = pq.reportFk
|
||||
WHERE pq.statusCode = 'queued'
|
||||
|
|
Loading…
Reference in New Issue