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