various small changes + almost complete ticket gen

This commit is contained in:
2023-08-01 14:26:46 +02:00
parent 836b56b69d
commit 581e7143f7
16 changed files with 118 additions and 46 deletions

View File

@@ -14,22 +14,31 @@ const db = require( '../db/db.js' );
class TicketGenerator {
constructor () {
this.ticketQueue = {};
this.jobId = 0;
this.isRunning = false;
}
// TODO: Save to disk in case of crash of server / reboot / whatever
// and continue processing once back online
generateTicket ( event, data ) {
this.ticketQueue [ this.jobId ] = { 'event': event, 'data': data };
this.jobId += 1;
this.queueHandler();
}
// TODO: Maybe move to subprocesses
queueHandler () {
if ( !this.isRunning ) {
this.isRunning = true;
this.ticketGenerator( this.ticketQueue[ Object.keys( this.ticketQueue )[ 0 ] ] ).then( res => {
this.ticketGenerator( this.ticketQueue[ this.jobId ][ 'event' ], this.ticketQueue[ this.jobId ][ 'data' ] ).then( pdf => {
console.log( pdf );
// TODO: Maybe write to disk
this.isRunning = false;
this.queueHandler();
} ).catch( error => {
console.error( '[ PDF GENERATOR ] ERROR: ' + error );
this.isRunning = false;
this.queueHandler();
// TODO: Add to FAILED db
} );
}