Add deadline header supporting (#12)

This commit is contained in:
Ildar Galeev 2020-09-10 17:26:05 +03:00 committed by GitHub
parent 686021930c
commit 14e154f78a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 5 deletions

5
package-lock.json generated
View File

@ -3118,6 +3118,11 @@
"minimist": "0.0.8"
}
},
"moment": {
"version": "2.27.0",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.27.0.tgz",
"integrity": "sha512-al0MUK7cpIcglMv3YF13qSgdAIqxHTO7brRtaz3DlSULbqfazqkc5kEjNrLDOM7fsjshoFIihnU8snrP7zUvhQ=="
},
"move-concurrently": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz",

View File

@ -18,17 +18,18 @@
"clean": "rimraf dist"
},
"dependencies": {
"babel-core": "6.26.3",
"babel-loader": "7.1.4",
"babel-preset-env": "1.7.0",
"base-x": "3.0.4",
"flake-idgen": "1.1.0",
"moment": "^2.27.0",
"node-int64": "0.4.0",
"q": "1.5.x",
"rimraf": "2.6.2",
"stream-http": "2.3.1",
"ws": "6.0.0",
"babel-core": "6.26.3",
"babel-loader": "7.1.4",
"babel-preset-env": "1.7.0",
"webpack": "4.16.5",
"webpack-cli": "3.1.0"
"webpack-cli": "3.1.0",
"ws": "6.0.0"
}
}

View File

@ -19,6 +19,7 @@
var util = require('util');
var http = require('stream-http');
var https = require('https');
var moment = require('moment');
var EventEmitter = require('events').EventEmitter;
var thrift = require('./thrift');
@ -225,6 +226,7 @@ HttpConnection.prototype.write = function (data) {
self.nodeOptions.headers['Content-length'] = data.length;
self.nodeOptions.headers['Accept'] = 'application/x-thrift';
self.nodeOptions.headers['Content-Type'] = 'application/x-thrift';
var id = bs64.encode(flake.next());
// Deprecated
@ -236,6 +238,13 @@ HttpConnection.prototype.write = function (data) {
self.nodeOptions.headers['woody.parent-id'] = undefined;
self.nodeOptions.headers['woody.trace-id'] = id;
if (self.options && self.options.deadlineConfig) {
var c = self.options.deadlineConfig;
var deadline = moment().add(c.amount, c.unitOfTime).utc().format();
self.nodeOptions.headers['x-rbk-deadline'] = deadline; // Deprecated
self.nodeOptions.headers['woody.deadline'] = deadline;
}
var req = (self.https) ?
https.request(self.nodeOptions, self.responseCallback) :
http.request(self.nodeOptions, self.responseCallback);

View File

@ -2,6 +2,22 @@ interface KeyValue {
[key: string]: any;
}
type UnitOfTime = (
'year' | 'years' | 'y' |
'month' | 'months' | 'M' |
'week' | 'weeks' | 'w' |
'day' | 'days' | 'd' |
'hour' | 'hours' | 'h' |
'minute' | 'minutes' | 'm' |
'second' | 'seconds' | 's' |
'millisecond' | 'milliseconds' | 'ms'
);
interface DeadlineConfig {
amount: number;
unitOfTime: UnitOfTime;
}
export interface ConnectOptions {
transport?: string;
protocol?: string;
@ -9,4 +25,5 @@ export interface ConnectOptions {
headers?: KeyValue;
https?: boolean;
nodeOptions?: object;
deadlineConfig?: DeadlineConfig
}

View File

@ -1,3 +1,5 @@
const webpack = require('webpack');
module.exports = {
name: 'woody_js',
mode: 'production',
@ -17,6 +19,10 @@ module.exports = {
}
]
},
plugins: [
// Ignore all locale files of moment.js
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
],
output: {
path: __dirname + '/dist',
filename: '[name].js',