diff --git a/bin/helpers/logger.js b/bin/helpers/logger.js index 7454b8b7..7563fce3 100644 --- a/bin/helpers/logger.js +++ b/bin/helpers/logger.js @@ -2,9 +2,6 @@ const winston = require('winston'), fs = require("fs"), path = require("path"); -const { format } = winston; -// const { format } = require("logform"); - const logDir = "log"; // directory path for logs if (!fs.existsSync(logDir)) { // Create the directory if it does not exist diff --git a/bin/helpers/usageReporting.js b/bin/helpers/usageReporting.js index a225c192..020b5613 100644 --- a/bin/helpers/usageReporting.js +++ b/bin/helpers/usageReporting.js @@ -1,7 +1,7 @@ 'use strict'; -const cp = require('child_process'), - os = require('os'), - request = require('request'), +const cp = require("child_process"), + os = require("os"), + request = require("requestretry"), fs = require('fs'), path = require('path'); @@ -188,19 +188,25 @@ function send(args) { url: config.usageReportingUrl, body: payload, json: true, + maxAttempts: 10, // (default) try 3 times + retryDelay: 2000, // (default) wait for 2s before trying again + retrySrategy: request.RetryStrategies.HTTPOrNetworkError, // (default) retry on 5xx or network errors }; - fileLogger.info(`Sending ${payload} to ${config.usageReportingUrl}`); + fileLogger.info(`Sending ${JSON.stringify(payload)} to ${config.usageReportingUrl}`); request(options, function (error, res, body) { if (error) { //write err response to file - fileLogger.err(JSON.stringify(error)); + fileLogger.error(JSON.stringify(error)); return; } - // write response and body to file - fileLogger.info( - `statusCode: ${res.statusCode}, body: ${JSON.stringify(body)}` - ); + // write response file + let response = { + attempts: res.attempts, + statusCode: res.statusCode, + body: body + }; + fileLogger.info(`${JSON.stringify(response)}`); }); } diff --git a/package.json b/package.json index f4c7f866..1ce65ef7 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,9 @@ "fs-extra": "^8.1.0", "mkdirp": "^1.0.3", "request": "^2.88.0", - "yargs": "^14.2.2", - "winston": "^2.3.1" + "requestretry": "^4.1.0", + "winston": "^2.3.1", + "yargs": "^14.2.2" }, "repository": { "type": "git",