rename subdomains.update to subdomains.upsert

This commit is contained in:
Girish Ramakrishnan
2016-09-05 16:41:04 -07:00
parent 4fc6eb1876
commit ecc9d1bc02
6 changed files with 12 additions and 24 deletions

View File

@@ -253,7 +253,7 @@ function registerSubdomain(app, callback) {
async.retry({ times: 200, interval: 5000 }, function (retryCallback) {
debugApp(app, 'Registering subdomain location [%s]', app.location);
subdomains.update(app.location, 'A', [ ip ], function (error, changeId) {
subdomains.upsert(app.location, 'A', [ ip ], function (error, changeId) {
if (error && (error.reason === SubdomainError.STILL_BUSY || error.reason === SubdomainError.EXTERNAL_ERROR)) return retryCallback(error); // try again
retryCallback(null, error || changeId);

View File

@@ -453,7 +453,7 @@ function addDnsRecords() {
debug('addDnsRecords: will update %j', records);
async.mapSeries(records, function (record, iteratorCallback) {
subdomains.update(record.subdomain, record.type, record.values, iteratorCallback);
subdomains.upsert(record.subdomain, record.type, record.values, iteratorCallback);
}, function (error, changeIds) {
if (error) debug('addDnsRecords: failed to update : %s. will retry', error);
else debug('addDnsRecords: records %j added with changeIds %j', records, changeIds);

View File

@@ -3,7 +3,7 @@
exports = module.exports = {
add: add,
del: del,
update: update,
upsert: upsert,
getChangeStatus: getChangeStatus,
get: get
};
@@ -69,7 +69,7 @@ function get(dnsConfig, zoneName, subdomain, type, callback) {
});
}
function update(dnsConfig, zoneName, subdomain, type, values, callback) {
function upsert(dnsConfig, zoneName, subdomain, type, values, callback) {
assert.strictEqual(typeof dnsConfig, 'object');
assert.strictEqual(typeof zoneName, 'string');
assert.strictEqual(typeof subdomain, 'string');
@@ -77,13 +77,7 @@ function update(dnsConfig, zoneName, subdomain, type, values, callback) {
assert(util.isArray(values));
assert.strictEqual(typeof callback, 'function');
get(dnsConfig, zoneName, subdomain, type, function (error, result) {
if (error) return callback(error);
if (_.isEqual(values, result)) return callback();
add(dnsConfig, zoneName, subdomain, type, values, callback);
});
add(dnsConfig, zoneName, subdomain, type, values, callback);
}
function del(dnsConfig, zoneName, subdomain, type, values, callback) {

View File

@@ -4,7 +4,7 @@ exports = module.exports = {
add: add,
get: get,
del: del,
update: update,
upsert: upsert,
getChangeStatus: getChangeStatus,
// not part of "dns" interface
@@ -113,7 +113,7 @@ function add(dnsConfig, zoneName, subdomain, type, values, callback) {
});
}
function update(dnsConfig, zoneName, subdomain, type, values, callback) {
function upsert(dnsConfig, zoneName, subdomain, type, values, callback) {
assert.strictEqual(typeof dnsConfig, 'object');
assert.strictEqual(typeof zoneName, 'string');
assert.strictEqual(typeof subdomain, 'string');
@@ -121,13 +121,7 @@ function update(dnsConfig, zoneName, subdomain, type, values, callback) {
assert(util.isArray(values));
assert.strictEqual(typeof callback, 'function');
get(dnsConfig, zoneName, subdomain, type, function (error, result) {
if (error) return callback(error);
if (_.isEqual(values, result)) return callback();
add(dnsConfig, zoneName, subdomain, type, values, callback);
});
add(dnsConfig, zoneName, subdomain, type, values, callback);
}
function get(dnsConfig, zoneName, subdomain, type, callback) {

View File

@@ -269,7 +269,7 @@ function startMail(callback) {
// Add MX record
var mxRecord = { subdomain: '', type: 'MX', values: [ '10 ' + config.mailFqdn() + '.' ] };
subdomains.update(mxRecord.subdomain, mxRecord.type, mxRecord.values, callback);
subdomains.upsert(mxRecord.subdomain, mxRecord.type, mxRecord.values, callback);
});
});
});

View File

@@ -4,7 +4,7 @@ module.exports = exports = {
add: add,
remove: remove,
status: status,
update: update, // unlike add, this fetches latest value, compares and adds if necessary. atomicity depends on backend
upsert: upsert,
get: get,
SubdomainError: SubdomainError
@@ -88,7 +88,7 @@ function get(subdomain, type, callback) {
});
}
function update(subdomain, type, values, callback) {
function upsert(subdomain, type, values, callback) {
assert.strictEqual(typeof subdomain, 'string');
assert.strictEqual(typeof type, 'string');
assert(util.isArray(values));
@@ -97,7 +97,7 @@ function update(subdomain, type, values, callback) {
settings.getDnsConfig(function (error, dnsConfig) {
if (error) return callback(new SubdomainError(SubdomainError.INTERNAL_ERROR, error));
api(dnsConfig.provider).update(dnsConfig, config.zoneName(), subdomain, type, values, function (error, changeId) {
api(dnsConfig.provider).upsert(dnsConfig, config.zoneName(), subdomain, type, values, function (error, changeId) {
if (error) return callback(error);
callback(null, changeId);