Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
serverConnection.on('data', (data) => {
let receivedData = JSON.parse(data);
if (receivedData.messageType === "CLI_UPLOAD_FILE") {
let filePath = receivedData.filePath;
batnode3.uploadFile(filePath);
} else if (receivedData.messageType === "CLI_DOWNLOAD_FILE") {
let filePath = receivedData.filePath;
batnode3.retrieveFile(filePath);
} else if (receivedData.messageType === "CLI_AUDIT_FILE") {
let filePath = receivedData.filePath;
let fibonacciBackoff = backoff.exponential({
randomisationFactor: 0,
initialDelay: 20,
maxDelay: 2000
});
console.log("received path: ", filePath);
batnode3.auditFile(filePath);
// post audit cleanup
serverConnection.on('close', () => {
batnode3._audit.ready = false;
batnode3._audit.data = null;
batnode3._audit.passed = false;
});
fibonacciBackoff.failAfter(10);
this.api = api;
Characteristic = this.api.hap.Characteristic;
Service = this.api.hap.Service;
this.log = log;
this.name = config.name;
this.serviceName = config.serviceName;
this.config = config;
this._isAnnounced = false;
this._isReachable = false;
this._playStatusUpdateListeners = [];
// Maximum backoff is 15mins when a device/program is visible
this._backoff = backoff.exponential({
initialDelay: 100,
maxDelay: 900000
}).on('backoff', (number, delay) => this._onBackoffStarted(delay))
.on('ready', () => this._connectToDacpDevice());
this._dacpClient = new DacpClient(log)
.on('failed', e => this._onDacpFailure(e));
this._services = this.createServices(this.api.hap);
}
constructor(createRequest, connection, cursor, params = {}) {
super(createRequest, connection, cursor, params);
this.createRequest = createRequest;
this.connection = connection;
this.cursor = cursor;
this.params = params;
if (!(this.connection instanceof require('../nylas-connection'))) {
throw new Error('Connection object not provided');
}
this.restartBackoff = backoff.exponential({
randomisationFactor: 0.5,
initialDelay: 250,
maxDelay: 30000,
factor: 4,
});
this.restartBackoff.failAfter(DeltaStream.MAX_RESTART_RETRIES);
this.restartBackoff
.on('backoff', this._restartConnection.bind(this))
.on('fail', () => {
return this.emit(
'error',
`Nylas DeltaStream failed to reconnect after
${DeltaStream.MAX_RESTART_RETRIES}
retries.`
);
});
function handleRunError(err) {
var errorBackoff = backoff.exponential(q._options.backoff);
errorBackoff.failAfter(q._options.maxRetries);
errorBackoff.on('ready', function() {
q.emit('retry', err);
run(q, key, JSON.parse(work), ranAgain);
});
errorBackoff.once('fail', function() {
q.emit('error', new Error('max retries reached'));
});
function ranAgain(err) {
if (err) errorBackoff.backoff();
else ran();
}
async asyncCallAssembleShards(completeFileSize, fileName, distinctShards) {
let exponentialBackoff = backoff.exponential({
randomisationFactor: 0,
initialDelay: 10,
maxDelay: 1000
});
const result = await this.sumShardsWhenFinish(completeFileSize, distinctShards, exponentialBackoff);
if (result === completeFileSize) {
fileUtils.assembleShards(fileName, distinctShards);
} else {
new Error(console.log("Error occurred, file size does not match manifest's record."));
}
}
function createExponentialBackoff() {
var exponentialBackoff = backoff.exponential({
initialDelay: 100,
maxDelay: 73000,
factor: 9
});
exponentialBackoff.failAfter(4);
return exponentialBackoff;
}
private findDevices() {
this.exponentialBackoff = backoff.exponential({
randomisationFactor: 0,
initialDelay: 1000,
maxDelay: 30000
});
this.exponentialBackoff.on('ready', (eventNumber, delay) => {
this.discoverAll(delay);
this.exponentialBackoff.backoff();
});
this.exponentialBackoff.backoff();
this.isRunning = true;
}