Skip to content

Commit

Permalink
Restored the init-code. Now run some tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fokko committed Jun 21, 2015
1 parent 0e45c3f commit c9546bb
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 73 deletions.
72 changes: 2 additions & 70 deletions lib/bootevent.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,5 @@
'use strict';

function boot(env, booted) {
require('./storage')(env, function ready(err, store) {

<<<<<<< HEAD
if(err)
console.warn('Could not succesfully connect to MongoDB.')

console.log('Storage system ready');
var ctx = {
store: store
};

///////////////////////////////////////////////////
// api and json object variables
///////////////////////////////////////////////////
ctx.plugins = require('./plugins')().registerServerDefaults().init(env);
ctx.pushnotify = require('./pushnotify')(env, ctx);
ctx.entries = require('./entries')(env, ctx);
ctx.treatments = require('./treatments')(env, ctx);
ctx.devicestatus = require('./devicestatus')(env.devicestatus_collection, ctx);
ctx.profile = require('./profile')(env.profile_collection, ctx);
ctx.pebble = require('./pebble')(env, ctx);

console.info("Ensuring indexes");
store.ensureIndexes(ctx.entries(), ctx.entries.indexedFields);
store.ensureIndexes(ctx.treatments(), ctx.treatments.indexedFields);
store.ensureIndexes(ctx.devicestatus(), ctx.devicestatus.indexedFields);
store.ensureIndexes(ctx.profile(), ctx.profile.indexedFields);

ctx.bus = require('./bus')(env, ctx);

ctx.data = require('./data')(env, ctx);
ctx.notifications = require('./notifications')(env, ctx);

function updateData() {
ctx.data.update(function dataUpdated() {
ctx.bus.emit('data-loaded');
});
}

ctx.bus.on('tick', function timedReloadData(tick) {
console.info('tick', tick.now);
updateData();
});

ctx.bus.on('data-received', function forceReloadData() {
console.info('got data-received event, reloading now');
updateData();
});

ctx.bus.on('data-loaded', function updatePlugins() {
var sbx = require('./sandbox')().serverInit(env, ctx);
ctx.plugins.setProperties(sbx);
ctx.notifications.initRequests();
ctx.plugins.checkNotifications(sbx);
ctx.notifications.process(sbx);
ctx.bus.emit('data-processed');
});

ctx.bus.on('notification', ctx.pushnotify.emitNotification);

ctx.bus.uptime();
=======
function boot (env) {

function setupMongo (ctx, next) {
Expand Down Expand Up @@ -141,19 +78,14 @@ function boot (env) {
next( );
}

var proc = bootevent( )
var proc = require('bootevent')( )
.acquire(setupMongo)
.acquire(setupInternals)
.acquire(ensureIndexes)
.acquire(setupListeners)
.acquire(finishBoot)
;
.acquire(finishBoot);

return proc;
>>>>>>> 8e87e10a8473c50566f929b9ebdd2b378ede2336

booted(ctx);
});
}

module.exports = boot;
2 changes: 1 addition & 1 deletion tests/api.entries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Entries REST api', function ( ) {
this.app = require('express')( );
this.app.enable('api');
var self = this;
require('../lib/bootevent')(env, function booted (ctx) {
require('../lib/bootevent')(env).boot(function booted (ctx) {
self.app.use('/', entries(self.app, self.wares, ctx));
self.archive = require('../lib/entries')(env, ctx);
self.archive.create(load('json'), done);
Expand Down
2 changes: 1 addition & 1 deletion tests/api.status.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Status REST api', function ( ) {
this.app = require('express')( );
this.app.enable('api');
var self = this;
require('../lib/bootevent')(env, function booted (ctx) {
require('../lib/bootevent')(env).boot(function booted (ctx) {
self.app.use('/api', api(env, ctx.entries));
done();
});
Expand Down
2 changes: 1 addition & 1 deletion tests/security.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('API_SECRET', function ( ) {

var scope = this;
function setup_app (env, fn) {
require('../lib/bootevent')(env, function booted (ctx) {
require('../lib/bootevent')(env).boot(function booted (ctx) {
var wares = require('../lib/middleware/')(env);
ctx.app = api(env, wares, ctx);
scope.app = ctx.app;
Expand Down

0 comments on commit c9546bb

Please sign in to comment.