kopia lustrzana https://github.com/c9/core
Add server-side latency (vfs -> docker host)
rodzic
aa36c77fac
commit
6f197414c3
|
@ -322,10 +322,30 @@ function Worker(vfs) {
|
|||
delete watchers[id];
|
||||
watcher.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add additional timing info to any "ping" call.
|
||||
*/
|
||||
function wrapPingCall(name, fnName, args) {
|
||||
if (name === "ping" && fnName === "ping" && args.length === 2) {
|
||||
var start = Date.now();
|
||||
var cb = args[1];
|
||||
|
||||
args[1] = function(err, payload) {
|
||||
if (err) return cb(err);
|
||||
cb(null, {
|
||||
payload: payload,
|
||||
serverTime: Date.now() - start
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function call(name, fnName, args) {
|
||||
var api = apis[name];
|
||||
if (!api) return;
|
||||
|
||||
wrapPingCall(name, fnName, args);
|
||||
|
||||
// If the last arg is a function, assume it's a callback and process it.
|
||||
if (typeof args[args.length - 1] == "function") {
|
||||
|
|
|
@ -60,11 +60,14 @@ define(function(require, exports, module) {
|
|||
if (!api) return callback(new Error("Client is offline"));
|
||||
|
||||
var start = Date.now();
|
||||
api.ping("ping", function(err) {
|
||||
api.ping("ping", function(err, response) {
|
||||
var took = Date.now() - start;
|
||||
if (err) return callback(err);
|
||||
|
||||
callback(null, took);
|
||||
callback(null, {
|
||||
serverTime: response.serverTime,
|
||||
total: took
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue