|
1 | 1 | 'use strict'; |
2 | | -const cp = require('child_process'), |
3 | | - os = require('os'), |
4 | | - request = require('request'), |
| 2 | +const cp = require("child_process"), |
| 3 | + os = require("os"), |
| 4 | + request = require("requestretry"), |
5 | 5 | fs = require('fs'), |
6 | 6 | path = require('path'); |
7 | 7 |
|
@@ -188,19 +188,25 @@ function send(args) { |
188 | 188 | url: config.usageReportingUrl, |
189 | 189 | body: payload, |
190 | 190 | json: true, |
| 191 | + maxAttempts: 10, // (default) try 3 times |
| 192 | + retryDelay: 2000, // (default) wait for 2s before trying again |
| 193 | + retrySrategy: request.RetryStrategies.HTTPOrNetworkError, // (default) retry on 5xx or network errors |
191 | 194 | }; |
192 | 195 |
|
193 | | - fileLogger.info(`Sending ${payload} to ${config.usageReportingUrl}`); |
| 196 | + fileLogger.info(`Sending ${JSON.stringify(payload)} to ${config.usageReportingUrl}`); |
194 | 197 | request(options, function (error, res, body) { |
195 | 198 | if (error) { |
196 | 199 | //write err response to file |
197 | | - fileLogger.err(JSON.stringify(error)); |
| 200 | + fileLogger.error(JSON.stringify(error)); |
198 | 201 | return; |
199 | 202 | } |
200 | | - // write response and body to file |
201 | | - fileLogger.info( |
202 | | - `statusCode: ${res.statusCode}, body: ${JSON.stringify(body)}` |
203 | | - ); |
| 203 | + // write response file |
| 204 | + let response = { |
| 205 | + attempts: res.attempts, |
| 206 | + statusCode: res.statusCode, |
| 207 | + body: body |
| 208 | + }; |
| 209 | + fileLogger.info(`${JSON.stringify(response)}`); |
204 | 210 | }); |
205 | 211 | } |
206 | 212 |
|
|
0 commit comments