ferrum-db-client
Advanced tools
Comparing version 0.3.14 to 0.3.15
import { FerrumDBRemote } from './db_remote'; | ||
import { DatabaseResponseMetrics, EventEmitter } from './util'; | ||
import { DatabaseResponseMetrics, EventEmitter, TimeoutData } from './util'; | ||
import { ConnectivityState } from '@grpc/grpc-js/build/src/connectivity-state'; | ||
@@ -21,3 +21,3 @@ export { FerrumDBRemote } from './db_remote'; | ||
readonly onResponseReceived: EventEmitter<DatabaseResponseMetrics>; | ||
readonly onTimeout: EventEmitter<string>; | ||
readonly onTimeout: EventEmitter<TimeoutData>; | ||
private onReconnect; | ||
@@ -24,0 +24,0 @@ private constructor(); |
@@ -84,2 +84,3 @@ "use strict"; | ||
reconnect() { | ||
const previousClient = this.client; | ||
this.client = new database_server_grpc_pb_1.DatabaseServerClient(`${this.ip}:${this.port}`, grpc_js_1.ChannelCredentials.createSsl(), { | ||
@@ -90,2 +91,3 @@ 'grpc.max_send_message_length': -1, | ||
this.onReconnect.emit(this.client.getChannel()); | ||
previousClient.close(); | ||
} | ||
@@ -92,0 +94,0 @@ async createDatabaseIfNotExists(dbName) { |
@@ -14,2 +14,6 @@ import { ServiceError } from '@grpc/grpc-js'; | ||
export declare function expandBsonBuffer(newSize: number): void; | ||
export interface TimeoutData { | ||
request: string; | ||
startTime: number; | ||
} | ||
export interface DatabaseResponseMetrics { | ||
@@ -22,3 +26,3 @@ request: string; | ||
startNotifier: EventEmitter<void>; | ||
timeoutNotifier: EventEmitter<string>; | ||
timeoutNotifier: EventEmitter<TimeoutData>; | ||
responseNotifier: EventEmitter<DatabaseResponseMetrics>; | ||
@@ -25,0 +29,0 @@ timeout: number; |
@@ -55,6 +55,10 @@ "use strict"; | ||
const startTime = performance.now(); | ||
const startTimeTs = Date.now(); | ||
let timeoutHandle; | ||
if (observerConfig.timeout > 0) { | ||
timeoutHandle = setTimeout(() => { | ||
observerConfig.timeoutNotifier.emit(printMessage(msg)); | ||
observerConfig.timeoutNotifier.emit({ | ||
request: printMessage(msg), | ||
startTime: startTimeTs, | ||
}); | ||
reject(new Error('Request timed out')); | ||
@@ -61,0 +65,0 @@ }, observerConfig.timeout); |
{ | ||
"name": "ferrum-db-client", | ||
"version": "0.3.14", | ||
"version": "0.3.15", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "typings": "dist/index.d.ts", |
@@ -7,3 +7,3 @@ import { ChannelCredentials } from '@grpc/grpc-js'; | ||
import { EmptyRequest } from './proto/shared_pb'; | ||
import { CallbackReturnType, DatabaseResponseMetrics, EventEmitter, ObserverConfig, performRPC } from './util'; | ||
import { CallbackReturnType, DatabaseResponseMetrics, EventEmitter, ObserverConfig, performRPC, TimeoutData } from './util'; | ||
import { ConnectivityState } from '@grpc/grpc-js/build/src/connectivity-state'; | ||
@@ -35,3 +35,3 @@ | ||
public readonly onResponseReceived: EventEmitter<DatabaseResponseMetrics> = new EventEmitter(); | ||
public readonly onTimeout: EventEmitter<string> = new EventEmitter(); | ||
public readonly onTimeout: EventEmitter<TimeoutData> = new EventEmitter(); | ||
private onReconnect: EventEmitter<Channel> = new EventEmitter(); | ||
@@ -99,2 +99,3 @@ | ||
public reconnect(): void { | ||
const previousClient = this.client; | ||
this.client = new DatabaseServerClient(`${this.ip}:${this.port}`, ChannelCredentials.createSsl(), { | ||
@@ -106,2 +107,3 @@ 'grpc.max_send_message_length': -1, | ||
this.onReconnect.emit(this.client.getChannel()); | ||
previousClient.close(); | ||
} | ||
@@ -108,0 +110,0 @@ |
@@ -49,2 +49,7 @@ import { ServiceError } from '@grpc/grpc-js'; | ||
export interface TimeoutData { | ||
request: string; | ||
startTime: number; | ||
} | ||
export interface DatabaseResponseMetrics { | ||
@@ -58,3 +63,3 @@ request: string; | ||
startNotifier: EventEmitter<void>; | ||
timeoutNotifier: EventEmitter<string>; | ||
timeoutNotifier: EventEmitter<TimeoutData>; | ||
responseNotifier: EventEmitter<DatabaseResponseMetrics>; | ||
@@ -68,6 +73,10 @@ timeout: number; | ||
const startTime = performance.now(); | ||
const startTimeTs = Date.now(); | ||
let timeoutHandle: NodeJS.Timeout; | ||
if (observerConfig.timeout > 0) { | ||
timeoutHandle = setTimeout(() => { | ||
observerConfig.timeoutNotifier.emit(printMessage(msg)); | ||
observerConfig.timeoutNotifier.emit({ | ||
request: printMessage(msg), | ||
startTime: startTimeTs, | ||
}); | ||
reject(new Error('Request timed out')); | ||
@@ -74,0 +83,0 @@ }, observerConfig.timeout); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1234473
28344