Closed joshbedo closed 8 years ago
nevermind got it working by looking at the hapiger implementation
@grahamjenson Actually i can't figure out how to initialize the namespace. I have this so far
'use strict';
var env = process.env.NODE_ENV;
import config from '../local.json';
import g from 'ger';
import ret_esm from 'ger_rethinkdb_esm';
var RethinkDBESM = ret_esm.esm; // rethinkdb event storage manager
var r = ret_esm.r; // rethinkdb ORM
var conn = r({
host: '192.168.99.100',
port: 28015,
db: 'matching'
});
var esm = new RethinkDBESM({r: conn})
var ger = new g.GER(esm);
/**
* Track actions like `bob`, `likes`, `jill` and
**/
export function trackEvent(params, done) {
ger.events([params.event])
.then((event) => {
done(null, params.event);
})
.catch((error) => {
done('Failed to save event: ', params.event);
});
}
/**
* Get recommendations for user and filter
* out user blacklisted ids.
**/
export function getRecommendations(params, done) {
}
Got this working by doing something like this
'use strict';
import g from 'ger';
import ret_esm from 'ger_rethinkdb_esm';
var RethinkDBESM = ret_esm.esm; // rethinkdb event storage manager
var r = ret_esm.r; // rethinkdb ORM
class MatchingService {
constructor(config) {
let conn = r(config.connection)
let esm = new RethinkDBESM({r: conn})
let ger = new g.GER(esm, {
logging_options: {
reporters: [{
reporter: require('good-console'),
events: { log: '*', response: '*' }
}]
}
});
// Create namespace if it doesnt exist (db tables)
ger.initialize_namespace(config.namespace)
.then((namespace) => {
console.info(`initialized ${config.namespace}:`, namespace)
})
this._ger = ger;
}
/**
* Track actions like `bob`, `likes`, `jill` and
**/
trackEvent(params, done) {
this._ger.events([params.event])
.then((event) => {
done(null, params.event);
})
.catch((error) => {
done('Failed to save event: ', params.event);
});
}
/**
* Get recommendations for user and filter
* out user blacklisted ids.
**/
getRecommendations(params, done) {
}
}
export default MatchingService
Hey, this was awesome. Cheers for contributing :)
Yeah namespaces are just buckets where events live, so one needs to be created before events go into it. I used to check before each event if the namespace exists and if it didnt create it. But this was a massive performance hit for something that would just be a one-off event.
Yeah i was confused originally because when i called initialize_namespace
tables weren't being created and i didn't have any errors. I think this was due to my docker containers connecting together since i have a container for rethinkdb and another for our matching service.
Also was a little confused on the ESM
setup and Rethinkdbdash
but it makes sense now. Thanks for putting together the ESM!
I console logged ger and i didn't see any ESM for rethinkdb