mirror of
https://github.com/janishutz/libreevent.git
synced 2025-11-25 13:24:24 +00:00
various small changes + almost complete ticket gen
This commit is contained in:
@@ -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
|
||||
} );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user