Created
December 3, 2015 15:27
-
-
Save zarko-tg/329ba811fd56ec118ce0 to your computer and use it in GitHub Desktop.
Queue processor using firebase-queue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const Queue = require( 'firebase-queue' ); | |
function EventsCollector ( app_name, firebase, keen_client ) { | |
this.app_name = app_name; | |
this.firebase = firebase; | |
this.keen_client = keen_client; | |
} | |
EventsCollector.prototype.setup = function () { | |
new Queue( this.firebase.child( 'event-job-queue' ), getProcessQueue( this ) ); | |
console.log( `Listening for client events from ${this.app_name} ...` ); | |
}; | |
function getProcessQueue ( context ) { | |
return ( data, progress, resolve, reject ) => { | |
let eventName = data.eventName; | |
data.keen = { timestamp : new Date( data.createdAt ).toISOString() }; | |
// Remove data we don't want in Keen.io | |
delete data.createdAt; | |
delete data.eventName; | |
context.keen_client.addEvent( eventName, data, err => { | |
if ( err ) { | |
let err_msg | |
= `Error adding event to Keen.io for ${context.app_name}` + err; | |
console.log( err_msg ); | |
reject( err_msg ); | |
return; | |
} | |
resolve(); | |
}); | |
}; | |
}; | |
module.exports = EventsCollector; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment