/** * Called whenever the connection to the WebSocket server is lost. */ onClose() { this.emit('debug', `[WS] closed`); if (!this.dead) this.client.setTimeout(this.connect.bind(this), this.attempts * 1000); }
/** * Starts connecting to the Voice WebSocket Server. */ connect() { this.emit('debug', `[WS] connect requested`); if (this.dead) return; if (this.ws) this.reset(); if (this.attempts >= 5) { this.emit('debug', new Error('VOICE_CONNECTION_ATTEMPTS_EXCEEDED', this.attempts)); return; } this.attempts++; /** * The actual WebSocket used to connect to the Voice WebSocket Server. * @type {WebSocket} */ this.ws = WebSocket.create(`wss://${this.connection.authentication.endpoint}/`, { v: 4 }); this.emit('debug', `[WS] connecting, ${this.attempts} attempts, ${this.ws.url}`); this.ws.onopen = this.onOpen.bind(this); this.ws.onmessage = this.onMessage.bind(this); this.ws.onclose = this.onClose.bind(this); this.ws.onerror = this.onError.bind(this); }
setTimeout(function(){ if (self.skipReconnect) return; debug('attempting reconnect'); self.emitAll('reconnect_attempt', self.backoff.attempts); self.emitAll('reconnecting', self.backoff.attempts); // check again for the case socket closed in above events if (self.skipReconnect) return; self.open(function(err){ if (err) { debug('reconnect attempt error'); self.reconnecting = false; self.reconnect(); self.emitAll('reconnect_error', err.data); } else { debug('reconnect success'); self.onreconnect(); } }); }, delay)
const attempts = (parseInt(loginMetadata.attempts, 10) || 0) + 1;
/** * Get the test's own max attempt count. Note that this is parasitically * inherited from its parent, not delegated. */ get attempts() { return this._.attempts }
/** * Set the number of attempts allowed, rounding negatives to 0. Setting the * count to `0` means to inherit the parent retry count. */ set attempts(attempts) { // This is done differently to avoid a massive performance penalty. var calculated = Math.floor(Math.max(attempts, 0)) var test = this._.root.current test.attempts = calculated || test.parent.attempts }
// Return true if we've either: // 1. passed this test, OR // 2. failed this test too many times canRun() { const canRetry = this.status === TEST_STATUS_FAILED && this.attempts < this.maxAttempts; const isNew = this.status === TEST_STATUS_NEW; return !isNew && !canRetry; }
this.q.create(name, data) .priority(options.priority || 'normal') .removeOnComplete(options.removeOnComplete || false) .attempts(options.attempts) .ttl((options.ttl ? options.ttl + this.ttl_buffer : 10000 + this.ttl_buffer )) // 10s .backoff(options.backoff) .delay(options.delay) .save(function(err){ debug('Add job ' + job.type + '(' + job.id + ') ' + JSON.stringify(data)) fn && fn(err) })
/** * Get the current attempt count. `0` means inherit the parent's. */ get attempts() { return this._.root.current.attempts }
setTimeout(function () { t.skipReconnect || (h("attempting reconnect"), t.emitAll("reconnect_attempt", t.backoff.attempts), t.emitAll("reconnecting", t.backoff.attempts), t.skipReconnect || t.open(function (e) { e ? (h("reconnect attempt error"), t.reconnecting = !1, t.reconnect(), t.emitAll("reconnect_error", e.data)) : (h("reconnect success"), t.onreconnect()) })) }, e)
/** * Get the test's own max attempt count. Note that this is parasitically * inherited from its parent, not delegated. */ get attempts() { return this._.attempts }
/** * Get the test's own max attempt count. Note that this is parasitically * inherited from its parent, not delegated. */ get attempts() { return this._.attempts }
/** * Get the current attempt count. `0` means inherit the parent's. */ get attempts() { return this._.root.current.attempts }
/** * Get the current attempt count. `0` means inherit the parent's. */ get attempts() { return this._.root.current.attempts }