Add connection-state tracking as getter
This commit is contained in:
parent
4e2ffec656
commit
d1cf1d8f7d
@ -24,12 +24,15 @@ class InfluxDbLineProtocolWriter extends net.Socket{
|
|||||||
options.autoReconnectBackoffTime ??= 3000;
|
options.autoReconnectBackoffTime ??= 3000;
|
||||||
this._options = options;
|
this._options = options;
|
||||||
|
|
||||||
|
this._isConnected = false;
|
||||||
|
|
||||||
super.setKeepAlive(true, 5000);
|
super.setKeepAlive(true, 5000);
|
||||||
|
|
||||||
// Register auto-Reconnect if enabled
|
// Register auto-Reconnect if enabled
|
||||||
if(this._options.autoReconnect){
|
if(this._options.autoReconnect){
|
||||||
this.on("connect", () => {
|
this.on("connect", () => {
|
||||||
logger.debug("Connection established!");
|
logger.debug("Connection established!");
|
||||||
|
this._isConnected = true;
|
||||||
|
|
||||||
if(this._autoReconnectTimeout)
|
if(this._autoReconnectTimeout)
|
||||||
clearInterval(this._autoReconnectTimeout);
|
clearInterval(this._autoReconnectTimeout);
|
||||||
@ -38,6 +41,8 @@ class InfluxDbLineProtocolWriter extends net.Socket{
|
|||||||
|
|
||||||
this.on("error", (err) => {
|
this.on("error", (err) => {
|
||||||
logger.error(err.code, "TCP ERROR");
|
logger.error(err.code, "TCP ERROR");
|
||||||
|
this._isConnected = false;
|
||||||
|
|
||||||
if(!this._autoReconnectTimeout)
|
if(!this._autoReconnectTimeout)
|
||||||
this._autoReconnectTimeout = setInterval(() => {
|
this._autoReconnectTimeout = setInterval(() => {
|
||||||
this.connect();
|
this.connect();
|
||||||
@ -53,6 +58,8 @@ class InfluxDbLineProtocolWriter extends net.Socket{
|
|||||||
get host(){ return this._host; }
|
get host(){ return this._host; }
|
||||||
get port(){ return this._port; }
|
get port(){ return this._port; }
|
||||||
|
|
||||||
|
get isConnected(){ return this._isConnected; }
|
||||||
|
|
||||||
connect(){
|
connect(){
|
||||||
logger.debug("Connecting..");
|
logger.debug("Connecting..");
|
||||||
super.connect(this._port, this._host);
|
super.connect(this._port, this._host);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user