Skip to content

Commit

Permalink
[minor] try to warm up and refresh the endpoints when ever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd-Eden committed Jan 8, 2013
1 parent 1323892 commit e161d44
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
44 changes: 39 additions & 5 deletions node.js/lib/client/apps.js
Expand Up @@ -35,10 +35,23 @@ Apps.prototype.list = function (username, callback) {
username = this.options.get('username');
}

var self = this;

this.request({ uri: ['apps', username] }, function (err, result, res) {
if (err) return callback(err);

callback(err, result.apps);

//
// Cache the lookups so we know which datacenters belong to the apps.
//
if (username === self.options.get('username')) {
result.apps.forEach(function reduce(memo, app) {
if (app.config) {
self.cloud[app._id] = app.config.cloud;
}
});
}
});
};

Expand All @@ -62,12 +75,21 @@ Apps.prototype.create = function (app, callback) {
//
Apps.prototype.view = function (appName, callback) {
appName = defaultUser.call(this, appName);
var argv = ['apps'].concat(appName.split('/'));
var argv = ['apps'].concat(appName.split('/')),
self = this;

this.request({ uri: argv }, function (err, result, res) {
this.request({ uri: argv }, function (err, result) {
if (err) return callback(err);

callback(err, result.app);
var app = result.app;
callback(err, app);

//
// Update the cloud cache.
//
if (app.config) {
self.clouds[appName] = app.config.cloud;
}
});
};

Expand Down Expand Up @@ -174,11 +196,21 @@ Apps.prototype.setDrones = function (appName, drones, callback) {
//
Apps.prototype.datacenter = function (appName, cloud, callback) {
appName = defaultUser.call(this, appName);
var argv = ['apps'].concat(appName.split('/')).concat('cloud');
var argv = ['apps'].concat(appName.split('/')).concat('cloud'),
self = this;

if (!Array.isArray(cloud)) cloud = [cloud];

this.request({ method: 'POST', uri: argv, body: cloud }, callback);
this.request({ method: 'POST', uri: argv, body: cloud }, function (err, result) {
if (err) return callback(err);

callback(err, result);

//
// Assume that this call invalidates our cached datacenter endpoint
//
delete self.clouds[appName];
});
};

//
Expand All @@ -187,9 +219,11 @@ Apps.prototype.datacenter = function (appName, cloud, callback) {
// Retrieves a list of currenlty active datacenters and providers
//
Apps.prototype.endpoints = function (callback) {
var self = this;
this.request({ uri: ['endpoints'] }, function (err, result) {
if (err) return callback(err);

self.datacenters = result.endpoints;
callback(err, result.endpoints);
});
};
1 change: 0 additions & 1 deletion node.js/lib/client/client.js
Expand Up @@ -30,7 +30,6 @@ var Client = exports.Client = function (options) {
return this[key];
};
}

};

util.inherits(Client, EventEmitter);
Expand Down

0 comments on commit e161d44

Please sign in to comment.