From 7a2dbfa26523435234b7b84da34fba39ffecaea5 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 16 Jan 2023 07:20:17 +0100 Subject: [PATCH] refs #4550 Changed updates --- config.yml | 3 ++- print-server.js | 21 +++++++++++++++++---- sql/selectQueued.sql | 2 +- sql/updateError.sql | 5 +++++ sql/{updateState.sql => updatePrinted.sql} | 2 +- sql/updatePrinting.sql | 7 +++++++ 6 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 sql/updateError.sql rename sql/{updateState.sql => updatePrinted.sql} (57%) create mode 100644 sql/updatePrinting.sql diff --git a/config.yml b/config.yml index 2f99fd5..6e63ea6 100644 --- a/config.yml +++ b/config.yml @@ -2,6 +2,7 @@ debug: false log: true dryPrint: false keepFile: false +serverId: 1 concurrency: 4 reconnectTimeout: 10 refreshRate: 1000 @@ -15,4 +16,4 @@ db: salix: url: http://localhost:3000 user: user - password: password + password: password \ No newline at end of file diff --git a/print-server.js b/print-server.js index c64d845..37c0a19 100644 --- a/print-server.js +++ b/print-server.js @@ -9,7 +9,9 @@ const yml = require('require-yml'); const selectQuery = fs.readFileSync(`sql/selectQueued.sql`).toString(); const jobDataQuery = fs.readFileSync(`sql/jobData.sql`).toString(); const jobArgsQuery = fs.readFileSync(`sql/jobArgs.sql`).toString(); -const updateQuery = fs.readFileSync(`sql/updateState.sql`).toString(); +const printingQuery = fs.readFileSync(`sql/updatePrinting.sql`).toString(); +const errorQuery = fs.readFileSync(`sql/updateError.sql`).toString(); +const printedQuery = fs.readFileSync(`sql/updatePrinted.sql`).toString(); class PrintServer { async start() { @@ -165,7 +167,14 @@ class PrintServer { const [[printJob]] = await conn.query(selectQuery); if (printJob) { jobId = printJob.id; - await conn.query(updateQuery, ['printing', null, jobId]); + await conn.query(printingQuery, [ + 'printing', + now(), + null, + null, + this.conf.serverId, + jobId + ]); this.jobLog(jobId, 'debug', 'get: printing'); await conn.commit(); } else @@ -274,11 +283,11 @@ class PrintServer { throw new Error(`Print error: ${err.message}`); } - await conn.query(updateQuery, ['printed', null, jobId]); + await conn.query(printedQuery, ['printed', now(), jobId]); this.jobLog(jobId, 'log', `${jobData.report}: '${printCommand}': GET ${url}`); } catch (err) { try { - await conn.query(updateQuery, ['error', err.message, jobId]); + await conn.query(errorQuery, ['error', now(), err.message, jobId]); } catch (e) { this.jobLog(jobId, 'error', e.message); } @@ -319,4 +328,8 @@ function pExec(command) { resolve({stdout, stderr}) }); }); +} + +function now() { + return new Date().toISOString().slice(0, 19).replace('T', ' '); } \ No newline at end of file diff --git a/sql/selectQueued.sql b/sql/selectQueued.sql index 5f8a588..590ca38 100644 --- a/sql/selectQueued.sql +++ b/sql/selectQueued.sql @@ -5,4 +5,4 @@ SELECT pq.id AND r.method IS NOT NULL ORDER BY pq.priorityFk ASC LIMIT 1 - FOR UPDATE + FOR UPDATE \ No newline at end of file diff --git a/sql/updateError.sql b/sql/updateError.sql new file mode 100644 index 0000000..f21dc20 --- /dev/null +++ b/sql/updateError.sql @@ -0,0 +1,5 @@ +UPDATE vn.printQueue + SET statusCode = ?, + finished = ?, + error = ? + WHERE id = ? \ No newline at end of file diff --git a/sql/updateState.sql b/sql/updatePrinted.sql similarity index 57% rename from sql/updateState.sql rename to sql/updatePrinted.sql index ee2e3cf..7a2b77d 100644 --- a/sql/updateState.sql +++ b/sql/updatePrinted.sql @@ -1,4 +1,4 @@ UPDATE vn.printQueue SET statusCode = ?, - error = ? + finished = ? WHERE id = ? \ No newline at end of file diff --git a/sql/updatePrinting.sql b/sql/updatePrinting.sql new file mode 100644 index 0000000..5361f54 --- /dev/null +++ b/sql/updatePrinting.sql @@ -0,0 +1,7 @@ +UPDATE vn.printQueue + SET statusCode = ?, + `started` = ?, + finished = ?, + error = ?, + serverId = ? + WHERE id = ? \ No newline at end of file