mirror of
https://github.com/Unitech/pm2.git
synced 2025-12-08 20:35:53 +00:00
let nssocket to his reconnect job in exponential backoff
This commit is contained in:
parent
ffc30d48f9
commit
cec23610c5
@ -4,68 +4,63 @@
|
||||
* can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
var debug = require('debug')('interface:driver'); // Interface
|
||||
var nssocket = require('nssocket');
|
||||
var Url = require('url');
|
||||
var Cipher = require('./Cipher.js');
|
||||
|
||||
var _gl_log_interval = null;
|
||||
|
||||
var util = require('util');
|
||||
var debug = require('debug')('interface:driver');
|
||||
var nssocket = require('nssocket');
|
||||
var Url = require('url');
|
||||
var Cipher = require('./Cipher.js');
|
||||
var util = require('util');
|
||||
|
||||
var ReverseInteract = {
|
||||
changeUrl : function(url) {
|
||||
if (!this.connected) return;
|
||||
console.log('[REV] Changing URL to %s', url);
|
||||
|
||||
// To enchance
|
||||
this.network = Url.parse(url);
|
||||
this.socket.connect(parseInt(this.network.port), this.network.hostname);
|
||||
this.socket.reconnect();
|
||||
},
|
||||
start : function(p) {
|
||||
if (!p.url)
|
||||
throw new Error('url not declared');
|
||||
if (!p.conf)
|
||||
throw new Error('Conf not passed to ReverseInteractor');
|
||||
|
||||
destroy : function() {
|
||||
this.socket.destroy();
|
||||
},
|
||||
start : function(opts) {
|
||||
var self = this;
|
||||
|
||||
this.connected = false;
|
||||
this.conf = p.conf;
|
||||
this.network = Url.parse(p.url);
|
||||
this.pm2_instance = p.conf.pm2_instance;
|
||||
if (!opts.url)
|
||||
throw new Error('url not declared');
|
||||
if (!opts.conf)
|
||||
throw new Error('Conf not passed to ReverseInteractor');
|
||||
|
||||
this.connected = false;
|
||||
this.conf = opts.conf;
|
||||
this.network = Url.parse(opts.url);
|
||||
this.pm2_instance = opts.conf.pm2_instance;
|
||||
|
||||
this.socket = new nssocket.NsSocket({
|
||||
type: 'tcp4'
|
||||
type : 'tcp4',
|
||||
reconnect : true,
|
||||
retryInterval : 100,
|
||||
max : Infinity,
|
||||
maxListeners : 50
|
||||
});
|
||||
|
||||
/**
|
||||
* Full duplex connect to AXM
|
||||
*/
|
||||
this.socket.on('error', function(e) {
|
||||
console.error('[REV] Error', e.message);
|
||||
self.connected = false;
|
||||
console.error('[REV] %s', e.message || e);
|
||||
});
|
||||
|
||||
this.socket.on('close', function(dt) {
|
||||
console.log('[REV] Connection closed');
|
||||
self.connected = false;
|
||||
setTimeout(function() {
|
||||
console.log('[REV] Retrying to connect %s:%s', self.network.hostname, self.network.port);
|
||||
self.socket.connect(parseInt(self.network.port), self.network.hostname);
|
||||
}, 2000);
|
||||
});
|
||||
|
||||
this.socket.on('start', function() {
|
||||
self.connected = true;
|
||||
p.conf.rev_con = true;
|
||||
opts.conf.rev_con = true;
|
||||
console.log('[REV] Connected to %s:%s', self.network.hostname, self.network.port);
|
||||
});
|
||||
|
||||
|
||||
console.log('[REV] Connecting to %s:%s', this.network.hostname, this.network.port);
|
||||
this.socket.connect(parseInt(this.network.port), this.network.hostname);
|
||||
|
||||
this.socket.connect(parseInt(this.network.port), this.network.hostname);
|
||||
this.onMessage();
|
||||
},
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user