Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"ampersand-sync-localforage": "^0.1.1",
"ampersand-view": "^8.0.0",
"ampersand-view-switcher": "^2.0.0",
"backoff": "^2.4.1",
"bootstrap": "https://github.com/twbs/bootstrap/archive/v3.3.5.tar.gz",
"browserify": "^10.2.4",
"bugsnag-js": "^2.4.8",
Expand Down Expand Up @@ -119,8 +120,8 @@
"mocha": "^2.2.5",
"moment": "^2.10.3",
"mongodb-extended-json": "^1.3.1",
"mongodb-js-precommit": "^0.2.2",
"mongodb-js-fmt": "^0.0.3",
"mongodb-js-precommit": "^0.2.2",
"mongodb-language-model": "^0.2.1",
"mongodb-schema": "^3.3.0",
"mousetrap": "^1.5.3",
Expand Down
59 changes: 41 additions & 18 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

var pkg = require('../package.json');
var app = require('ampersand-app');
var backoff = require('backoff');

app.extend({
// @todo (imlucas) Move to config
// `scout-server` to point at.
Expand Down Expand Up @@ -30,6 +32,31 @@ var Statusbar = require('./statusbar');

var debug = require('debug')('scout:app');

function getConnection(model, done) {
function _fetch(fn) {
model.fetch({
success: function() {
debug('_fetch connection succeeded!');
fn();
},
error: function() {
debug('_fetch connection failed', arguments);
fn(new Error('Error retrieving connection details'));
}
});
}

var call = backoff.call(_fetch, done);
call.setStrategy(new backoff.ExponentialStrategy({
randomisationFactor: 0,
initialDelay: 10,
maxDelay: 500
}));
call.failAfter(10);
call.start();
}


// Inter-process communication with main process (Electron window)
var ipc = window.require('ipc');

Expand Down Expand Up @@ -253,25 +280,21 @@ app.extend({
});

debug('looking up connection `%s`...', connection_id);
state.connection.fetch({
success: function() {
app.statusbar.show('Connection details loaded! Initializing client...');

var endpoint = app.endpoint;
var connection = state.connection.serialize();

app.client = getOrCreateClient(endpoint, connection)
.on('readable', state.onClientReady.bind(state))
.on('error', state.onFatalError.bind(state, 'create client'));

state.startClientStalledTimer();
},
error: function() {
// @todo (imlucas) `ampersand-sync-localforage` currently drops
// the real error so for now just use a generic.
state.onFatalError(state, 'fetch connection',
new Error('Error retrieving connection. Please reload the page.'));
getConnection(state.connection, function(err) {
if (err) {
state.onFatalError('fetch connection', err);
return;
}
app.statusbar.show('Connecting to MongoDB...');

var endpoint = app.endpoint;
var connection = state.connection.serialize();

app.client = getOrCreateClient(endpoint, connection)
.on('readable', state.onClientReady.bind(state))
.on('error', state.onFatalError.bind(state, 'create client'));

state.startClientStalledTimer();
});
});
// set up ipc
Expand Down