Skip to content

Instantly share code, notes, and snippets.

@tzmartin
Forked from zarko-tg/gist:329ba811fd56ec118ce0
Created December 25, 2015 07:03
Show Gist options
  • Save tzmartin/89b98ff374c6a135508b to your computer and use it in GitHub Desktop.
Save tzmartin/89b98ff374c6a135508b to your computer and use it in GitHub Desktop.
Queue processor using firebase-queue
'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