Skip to content

Commit

Permalink
Update configureService and call sites to new service format.
Browse files Browse the repository at this point in the history
The `configure` callback now gets called with a list of endpoints for the
service instead of a Services document.
  • Loading branch information
Emily Stark committed Dec 24, 2013
1 parent b196ba4 commit 2ed30c5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 20 deletions.
45 changes: 40 additions & 5 deletions packages/application-configuration/config.js
Expand Up @@ -149,15 +149,50 @@ AppConfig.configurePackage = function (packageName, configure) {
};
};

AppConfig.configureService = function (serviceName, configure) {
AppConfig.configureService = function (serviceName, version, configure) {

// Collect all the endpoints for this service, from both old- and new-format
// documents, and call the `configure` callback with all the service endpoints
// that we know about.
var callConfigure = function (doc) {
var serviceDocs = Services.find({
name: serviceName,
version: version
});
var endpoints = [];
serviceDocs.forEach(function (serviceDoc) {
if (serviceDoc.providers) {
_.each(serviceDoc.providers, function (endpoint, app) {
endpoints.push(endpoint);
});
} else {
endpoints.push(serviceDoc.endpoint);
}
});
configure(endpoints);
};

if (ultra) {
// there's a Meteor.startup() that produces the various collections, make
// sure it runs first before we continue.
collectionFuture.wait();
ultra.subscribe('servicesByName', serviceName);
return Services.find({name: serviceName}).observe({
added: configure,
changed: configure
// First try to subscribe to the new format service registrations; if that
// sub doesn't exist, then ultraworld hasn't updated to the new format yet,
// so try the old format `servicesByName` sub instead.
ultra.subscribe('services', serviceName, version, {
onError: function (err) {
if (err.error === 404) {
ultra.subscribe('servicesByName', serviceName);
}
}
});
return Services.find({
name: serviceName,
version: version
}).observe({
added: callConfigure,
changed: callConfigure,
removed: callConfigure
});
}

Expand Down
26 changes: 14 additions & 12 deletions packages/ctl-helper/ctl-helper.js
Expand Up @@ -139,18 +139,20 @@ _.extend(Ctl, {
updateProxyActiveTags: function (tags) {
var proxy;
var proxyTagSwitchFuture = new Future;
AppConfig.configureService('proxy', function (proxyService) {
try {
proxy = Follower.connect(proxyService.providers.proxy, {
group: "proxy"
});
proxy.call('updateTags', Ctl.myAppName(), tags);
proxy.disconnect();
if (!proxyTagSwitchFuture.isResolved())
proxyTagSwitchFuture['return']();
} catch (e) {
if (!proxyTagSwitchFuture.isResolved())
proxyTagSwitchFuture['throw'](e);
AppConfig.configureService('proxy', 'pre0', function (proxyService) {
if (proxyService && ! _.isEmpty(proxyService)) {
try {
proxy = Follower.connect(proxyService, {
group: "proxy"
});
proxy.call('updateTags', Ctl.myAppName(), tags);
proxy.disconnect();
if (!proxyTagSwitchFuture.isResolved())
proxyTagSwitchFuture['return']();
} catch (e) {
if (!proxyTagSwitchFuture.isResolved())
proxyTagSwitchFuture['throw'](e);
}
}
});

Expand Down
7 changes: 4 additions & 3 deletions packages/webapp/webapp_server.js
Expand Up @@ -580,8 +580,9 @@ var runWebAppServer = function () {
// on a per-job basis. Discuss w/ teammates.
proxyBinding = AppConfig.configureService(
"proxy",
"pre0",
function (proxyService) {
if (proxyService.providers.proxy) {
if (proxyService && ! _.isEmpty(proxyService)) {
var proxyConf;
// XXX Figure out a per-job way to specify bind location
// (besides hardcoding the location for ADMIN_APP jobs).
Expand All @@ -602,9 +603,9 @@ var runWebAppServer = function () {
proxyConf = configuration.proxy;
}
Log("Attempting to bind to proxy at " +
proxyService.providers.proxy);
proxyService);
WebAppInternals.bindToProxy(_.extend({
proxyEndpoint: proxyService.providers.proxy
proxyEndpoint: proxyService
}, proxyConf));
}
}
Expand Down

0 comments on commit 2ed30c5

Please sign in to comment.