mirror of
https://github.com/mclueppers/xo-server.git
synced 2025-07-27 07:54:54 +02:00
Various updates.
This commit is contained in:
parent
e703824198
commit
9a813adf0e
25
src/xapi.js
25
src/xapi.js
@ -19,10 +19,12 @@ require('util').inherits(Xapi, require('events').EventEmitter);
|
|||||||
|
|
||||||
Xapi.prototype.call = function (method) {
|
Xapi.prototype.call = function (method) {
|
||||||
var args = arguments;
|
var args = arguments;
|
||||||
var params = Array.prototype.slice.call(arguments, 1);
|
var tries = 0;
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
return function helper() {
|
||||||
return Q(self.sessionId).then(function (session_id) {
|
return Q(self.sessionId).then(function (session_id) {
|
||||||
|
var params = Array.prototype.slice.call(args, 1);
|
||||||
if (session_id)
|
if (session_id)
|
||||||
{
|
{
|
||||||
params.unshift(session_id);
|
params.unshift(session_id);
|
||||||
@ -42,14 +44,29 @@ Xapi.prototype.call = function (method) {
|
|||||||
|
|
||||||
return value.Value;
|
return value.Value;
|
||||||
}).fail(function (error) {
|
}).fail(function (error) {
|
||||||
if ('HOST_IS_SLAVE' !== error[0])
|
|
||||||
|
// XAPI sommetimes close the connection when the server is
|
||||||
|
// no longer pool master (`event.next`), so we have to
|
||||||
|
// retry at least once to know who is the new pool master.
|
||||||
|
if ((0 === tries) && ('ECONNRESET' === error.code))
|
||||||
{
|
{
|
||||||
throw error;
|
// @todo Does not work because it seems to reuse the
|
||||||
|
// broken socket.
|
||||||
|
|
||||||
|
++tries;
|
||||||
|
return helper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('HOST_IS_SLAVE' === error[0])
|
||||||
|
{
|
||||||
|
tries = 0;
|
||||||
self.changeHost(error[1]);
|
self.changeHost(error[1]);
|
||||||
return self.call.apply(self, args);
|
return helper();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
});
|
});
|
||||||
|
}();
|
||||||
};
|
};
|
||||||
|
|
||||||
Xapi.prototype.changeHost = function (host) {
|
Xapi.prototype.changeHost = function (host) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user