Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[refactor] Create unique worker socket files using the `microtime` mo…

…dule
  • Loading branch information...
commit 1fa4943afb87cfdf42dfb4f21b8a757e63eb2ade 1 parent 72dac45
@indexzero indexzero authored
Showing with 15 additions and 27 deletions.
  1. +3 −0  examples/cli-multiple-start
  2. +11 −27 lib/forever/worker.js
  3. +1 −0  package.json
View
3  examples/cli-multiple-start
@@ -0,0 +1,3 @@
+forever start examples/server.js -p 8080
+forever start examples/server.js -p 8081
+forever start examples/server.js -p 8082
View
38 lib/forever/worker.js
@@ -1,29 +1,11 @@
var events = require('events'),
fs = require('fs'),
path = require('path'),
+ microtime = require('microtime'),
nssocket = require('nssocket'),
utile = require('utile'),
forever = require('../forever');
-function findSocket(sockPath, startAt, callback) {
- if (typeof startAt == "function") {
- callback = startAt;
- startAt = null;
- }
-
- startAt || (startAt = 0);
- var sock = path.join(sockPath, 'worker.' + startAt + '.sock');
- fs.stat(sock, function (err, stat) {
- if (err) {
- return err.code == 'ENOENT'
- ? callback(null, sock)
- : callback(err);
- }
-
- return findSocket(sockPath, ++startAt, callback);
- });
-}
-
var Worker = exports.Worker = function (options) {
events.EventEmitter.call(this);
options || (options = {});
@@ -116,14 +98,16 @@ Worker.prototype.start = function (callback) {
callback && callback(err);
});
- findSocket(self.sockPath, function (err, sock) {
- if (err) {
- return callback && callback(err);
- }
-
- self._sockFile = sock;
- self._socket.listen(sock);
- });
+ //
+ // Create a unique socket file based on the current microtime.
+ //
+ var sock = self._sockFile = path.join(self.sockPath, [
+ 'worker',
+ microtime.nowStruct().join(''),
+ 'sock'
+ ].join('.'));
+
+ self._socket.listen(sock);
}
//
View
1  package.json
@@ -27,6 +27,7 @@
"cliff": "0.x.x",
"daemon": "0.4.x",
"flatiron": "0.1.x",
+ "microtime": "0.2.x",
"minimatch": "0.0.x",
"nconf": "0.5.x",
"nssocket": "0.3.x",
Please sign in to comment.
Something went wrong with that request. Please try again.