Permalink
Browse files

allow opts.name to set the drone name and auto-increment on a number …

…in the case of conflicts
  • Loading branch information...
1 parent 84fce05 commit f0e695f8777d6c780566c63de647eea85d1fec46 @substack committed Aug 2, 2012
Showing with 17 additions and 3 deletions.
  1. +16 −2 index.js
  2. +1 −1 package.json
View
18 index.js
@@ -38,6 +38,7 @@ function Propagit (opts) {
var base = opts.basedir || process.cwd();
this.repodir = path.resolve(opts.repodir || base + '/repos');
this.deploydir = path.resolve(opts.deploydir || base + '/deploy');
+ this.name = opts.name || (Math.random() * Math.pow(16,8)).toString(16);
if (opts.hub) this.connect(opts.hub);
}
@@ -134,7 +135,7 @@ Propagit.prototype.getDrones = function (opts) {
return opts.drone.test(d.id);
});
}
- if (names) {
+ if (Array.isArray(names) && names.length) {
return names.map(function (name) {
var ix = ids.indexOf(name);
return self.drones[ix];
@@ -245,6 +246,19 @@ Propagit.prototype.createService = function (remote, conn) {
service.register = function (role, obj) {
if (role === 'drone') {
+ if (typeof obj !== 'object') return;
+ obj.id = String(obj.id);
+ var ids = self.drones.map(function (d) { return d.id });
+ if (ids.indexOf(obj.id) >= 0 && !/-\d+$/.test(obj.id)) {
+ obj.id += '-1';
+ }
+
+ while (ids.indexOf(obj.id) >= 0) {
+ obj.id.replace(/-(\d+)/, function (_, x) {
+ return x + 1
+ });
+ }
+
self.drones.push(obj);
conn.on('end', function () {
@@ -451,7 +465,7 @@ Propagit.prototype.drone = function (fn) {
cb(id);
};
- actions.id = (Math.random() * Math.pow(16,8)).toString(16);
+ actions.id = self.name;
if (typeof fn === 'function') fn.call(self, actions);
self.middleware.forEach(function (m) {
View
2 package.json
@@ -1,7 +1,7 @@
{
"name" : "propagit",
"description" : "cascading multi-server git deployment",
- "version" : "0.6.2",
+ "version" : "0.6.3",
"repository" : {
"type" : "git",
"url" : "git://github.com/substack/propagit.git"

0 comments on commit f0e695f

Please sign in to comment.