Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var retryOnHTTPNetOrEuPMCFailure = function (err, response, body) {
return requestretry.RetryStrategies.HTTPOrNetworkError(err, response, body) ||
~body.indexOf('') // hacky way to see if resultsList is empty
}
MODE_OC,
} from './FeedUploaderConstants';
import {getLogger, getLoggerAWS} from './Logger';
import {getValidEvents} from './RequestDataBuilder';
import {
UNSUPPORTED_MODE,
ERROR_NO_CA_ID_OR_ACT_ID,
} from './ErrorTypes';
const querystring = require('querystring');
const request = require('requestretry');
const APIErrorTypes = require('./APIErrorTypes');
const MAX_RETRIES = 10; // Retry 10 times.
const RETRY_DELAY = 5000; // Wait 5s before trying again.
const RETRY_STRATEGY = request.RetryStrategies.HTTPOrNetworkError; // retry on 5xx or network errors.
export const uploadEventsBatch = (
events: Array,
postData: string,
uploadSessionTag: string,
fileOffset: number,
configs: FeedUploaderConfigs,
callback: batchUploadCallbackType,
): void => {
// Do the real uploading (calling into graph API) if not silent.
if (configs.silent !== true) {
getLogger().info(
`Posting rows ${getBatchSigStr({offset: fileOffset, size: events.length})} to \
${datasetEndpoint(configs)}`
);
_postEvents(events, postData, fileOffset, configs, uploadSessionTag, callback);
// seperate pool for species requests as that API often has outages.
const speciesAgent = new Agent({
maxSockets: 8000, // Default = Infinity
maxFreeSockets: 256, // default
keepAlive: true,
keepAliveMsecs: 1000
});
let speciesRequest = request.defaults({
agent: speciesAgent,
headers: {
'User-Agent': 'GBIF-portal Occurrence'
},
maxAttempts: 1,
retryDelay: 3000, // in milliseconds
retryStrategy: request.RetryStrategies.HTTPOrNetworkError, // (default) retry on 5xx or network errors
timeout: 45000 // in milliseconds
});
module.exports = {
standard: stdRequest,
occurrence: occurrenceRequest,
species: speciesRequest
};
OutputInflux.prototype.send = function (body) {
if (this.config.debug) {
consoleLogger.log('output-influxdb: influx line protocol format \n\t' + body.replace(/\n/g, '\n\t'))
}
var self = this
var options = {
method: 'post',
url: this.config.url + '/write?db=' + self.config.db,
body: body,
maxAttempts: 20,
retryDelay: 3000,
retryStrategy: request.RetryStrategies.HTTPOrNetworkError
}
request(options, function (err, response, body) {
if (self.config.debug === true && response && response.attempts) {
consoleLogger.log('output-influxdb: ' + response.attempts + ' attempts ' + ' ' + options.url + ' ' + body + ' ' + response.statusCode)
}
if (err) {
self.eventEmitter.emit('error', err)
}
})
}
OutputHttp.prototype.send = function (body) {
if (this.config.debug) {
consoleLogger.log('output-http: ' + body.replace(/\n/g, '\n\t'))
}
var self = this
var options = {
method: 'post',
url: this.config.url,
body: body,
maxAttempts: 20,
retryDelay: 3000,
retryStrategy: request.RetryStrategies.HTTPOrNetworkError
}
request(options, function (err, response, body) {
if (self.config.debug === true && response && response.attempts) {
consoleLogger.log('output-http: ' + response.attempts + ' attempts ' + ' ' + options.url + ' ' + body + ' ' + response.statusCode)
}
if (err) {
self.eventEmitter.emit('error', err)
}
})
}
SessionManager.prototype._getWebdriverSessions = function (callback) {
var wdHubSessions = 'http://' + this.options.host + ':' + this.options.port + '/wd/hub/sessions';
log.debug('[chimp][session-manager]', 'requesting sessions from', wdHubSessions);
requestretry({
url: wdHubSessions,
maxAttempts: 10,
retryDelay: 500,
retryStrategy: requestretry.RetryStrategies.HTTPOrNetworkError
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
log.debug('[chimp][session-manager]', 'received data', body);
callback(null, JSON.parse(body).value);
} else {
log.error('[chimp][session-manager]', 'received error', error, 'response', response);
callback(error);
}
});
};
return new Promise((resolve) => {
log.debug(`trying to call ${type} webhook ${url} (${pipelineStatus})`, { component });
const data = {
url,
pipelineStatus,
status: States.COMPLETED
};
request({
method: 'POST',
uri: url,
body,
json: true,
maxAttempts: this._options.webhooks.retryStrategy.maxAttempts,
retryDelay: this._options.webhooks.retryStrategy.retryDelay,
retryStrategy: request.RetryStrategies.HTTPOrNetworkError
}).then((response) => {
data.responseStatus = response.statusCode >= 400 ? States.FAILED : States.SUCCEED;
data.httpResponse = { statusCode: response.statusCode, statusMessage: response.statusMessage };
log.debug(`${type} webhook has been sent with status ${response.statusCode} ${response.statusMessage}, attempts: ${response.attempts}`, { component, jobId });
return resolve(data);
}).catch((error) => {
data.responseStatus = States.FAILED;
data.httpResponse = { statusCode: error.code, statusMessage: error.message };
log.warning(`webhook ${type} failed ${error.message}`, { component, jobId });
return resolve(data);
});
});
}
},()=>{
let jar = self.props.auth.cookie;
request({
uri: URL_PAGES,
jar: jar,
maxAttempts: 5,
retryDelay: 5000,
retryStrategy: request.RetryStrategies.HTTPOrNetworkError
},(err,response,body) => {
let data = JSON.parse(body);
self.setState({
pages: data,
statusTextDl : 'Carregando Paginas...',
},()=>{
let l = data.length;
let lSplit = data.length/3;
let d1 = data.slice(0,Math.floor(lSplit));
let d2 = data.slice(lSplit, lSplit*2 );
let d3 = data.slice(lSplit*2, l);