MCPcopy Create free account
hub / github.com/apache/cassandra-nodejs-driver / _init

Method _init

lib/insights-client.js:90–118  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

88 }
89
90 async _init() {
91 try {
92 await this._sendStartupEvent();
93
94 if (this._closed) {
95 // The client was shutdown
96 return;
97 }
98
99 // Send the status event the first time with a delay containing some random portion
100 // Initial delay should be statusEventDelay - (0 to 10%)
101 const firstDelay = Math.floor(this._statusEventDelay - 0.1 * this._statusEventDelay * Math.random());
102 // Schedule the first timer
103 this._firstTimeout = setTimeout(() => {
104 // Send the first status event, the promise will never be rejected
105 this._sendStatusEvent();
106 // The following status events are sent at regular intervals
107 this._recurrentTimeout = setInterval(() => this._sendStatusEvent(), this._statusEventDelay);
108 }, firstDelay);
109 } catch (err) {
110 if (this._closed) {
111 // Sending failed because the Client was shutdown
112 return;
113 }
114 // We shouldn't try to recover
115 this._client.log('verbose', `Insights startup message could not be sent (${err})`, err);
116 this._errorCallback(err);
117 }
118 }
119
120 /**
121 * Sends the startup event.

Callers 1

initMethod · 0.95

Calls 2

_sendStartupEventMethod · 0.95
_sendStatusEventMethod · 0.95

Tested by

no test coverage detected