grpc-code-gen
Advanced tools
Comparing version 4.0.2 to 4.1.0
@@ -449,2 +449,4 @@ "use strict"; | ||
` | ||
const maxTry = 3; | ||
Object.keys(${service.name}.prototype).forEach((key) => { | ||
@@ -455,2 +457,4 @@ if (!/^\\$/.test(key)) { | ||
${service.name}.prototype[key] = promisify(function(request, options, callback) { | ||
let count = 0; | ||
if (typeof callback !== 'undefined') { | ||
@@ -463,16 +467,29 @@ options = Object.assign({}, callOptions, options) || {}; | ||
if (typeof options.timeout === 'number') { | ||
options.deadline = Date.now() + options.timeout; | ||
function doCall(self: any) { | ||
if (typeof options.timeout === 'number') { | ||
options.deadline = Date.now() + options.timeout; | ||
} | ||
const start = Date.now(); | ||
(origin as any).apply(self, [request, options, function(err: any, response: any) { | ||
if (!logOptions.disable) { | ||
const duration = (Date.now() - start) / 1000; | ||
console.info('grpc invoke:', methodId, 'duration:', duration + 's', 'request:', JSON.stringify(request)); | ||
if (err) { | ||
console.error('grpc invoke:', methodId, 'duration:', duration + 's', 'request:', JSON.stringify(request), 'err:', err); | ||
} | ||
} | ||
if (count < maxTry && /^Internal HTTP2 error/.test(err.details || err.message || err.data)) { | ||
count++; | ||
setTimeout(() => { | ||
doCall(self); | ||
}, 25); | ||
} else { | ||
callback(err, response); | ||
} | ||
}]); | ||
} | ||
return origin.apply(this, [request, options, function(err: any, response: any) { | ||
if (!logOptions.disable) { | ||
const duration = (Date.now() - start) / 1000; | ||
console.info('grpc invoke:', methodId, 'duration:', duration + 's', 'request:', JSON.stringify(request)); | ||
if (err) { | ||
console.error('grpc invoke:', methodId, 'duration:', duration + 's', 'request:', JSON.stringify(request), 'err:', err); | ||
} | ||
} | ||
callback(err, response); | ||
}]); | ||
doCall.call(this); | ||
}); | ||
@@ -479,0 +496,0 @@ } |
{ | ||
"name": "grpc-code-gen", | ||
"version": "4.0.2", | ||
"version": "4.1.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/yunkeCN/grpc-code-gen.git", |
@@ -527,2 +527,4 @@ import * as fs from 'fs-extra'; | ||
` | ||
const maxTry = 3; | ||
Object.keys(${service.name}.prototype).forEach((key) => { | ||
@@ -533,2 +535,4 @@ if (!/^\\$/.test(key)) { | ||
${service.name}.prototype[key] = promisify(function(request, options, callback) { | ||
let count = 0; | ||
if (typeof callback !== 'undefined') { | ||
@@ -541,16 +545,29 @@ options = Object.assign({}, callOptions, options) || {}; | ||
if (typeof options.timeout === 'number') { | ||
options.deadline = Date.now() + options.timeout; | ||
function doCall(self: any) { | ||
if (typeof options.timeout === 'number') { | ||
options.deadline = Date.now() + options.timeout; | ||
} | ||
const start = Date.now(); | ||
(origin as any).apply(self, [request, options, function(err: any, response: any) { | ||
if (!logOptions.disable) { | ||
const duration = (Date.now() - start) / 1000; | ||
console.info('grpc invoke:', methodId, 'duration:', duration + 's', 'request:', JSON.stringify(request)); | ||
if (err) { | ||
console.error('grpc invoke:', methodId, 'duration:', duration + 's', 'request:', JSON.stringify(request), 'err:', err); | ||
} | ||
} | ||
if (count < maxTry && /^Internal HTTP2 error/.test(err.details || err.message || err.data)) { | ||
count++; | ||
setTimeout(() => { | ||
doCall(self); | ||
}, 25); | ||
} else { | ||
callback(err, response); | ||
} | ||
}]); | ||
} | ||
return origin.apply(this, [request, options, function(err: any, response: any) { | ||
if (!logOptions.disable) { | ||
const duration = (Date.now() - start) / 1000; | ||
console.info('grpc invoke:', methodId, 'duration:', duration + 's', 'request:', JSON.stringify(request)); | ||
if (err) { | ||
console.error('grpc invoke:', methodId, 'duration:', duration + 's', 'request:', JSON.stringify(request), 'err:', err); | ||
} | ||
} | ||
callback(err, response); | ||
}]); | ||
doCall.call(this); | ||
}); | ||
@@ -557,0 +574,0 @@ } |
Sorry, the diff of this file is not supported yet
129802
1934