Skip to content

Commit 1799ea0

Browse files
committed
Add retryAfterMSec option
1 parent 6accc4d commit 1799ea0

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ The Bulk Data Client uses `js` configuration files, but you can think of them as
132132
- *boolean* **`log.enabled`** - Set this to false to disable logging. Optional (defaults to true).
133133
- *string* **`log.file`** - Path to the log file. Absolute, or relative to process CWD. If not provided, the file will be called log.ndjson and will be stored in the downloads folder.
134134
- *object* **`log.metadata`** - Key/value pairs to be added to every log entry. Can be used to add useful information (for example which site imported this data).
135+
- *number* **`retryAfterMSec`** - If the server does not provide `Retry-after` header use this number of milliseconds before checking the status again.
135136

136137

137138
### Environment Variables
@@ -173,6 +174,7 @@ Note that you can pass a `--help` parameter to see this listed in your terminal
173174
| | `--config` | Relative path to config file |
174175
| | `--reporter` | Reporter to use to render the output. "cli" renders fancy progress bars and tables. "text" is better for log files. Defaults to "cli" |
175176
| `-c` | `--custom` | Custom parameters to be passed to the kick-off endpoint. Example: `-c a=1 b=c` |
177+
| | `--status` | If a status request fails for some reason the client will exit. However, if the status endpoint is printed in the output, you can retry by passing it as `--status` option here |
176178

177179

178180
Features

built/lib/BulkDataClient.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,15 @@ class BulkDataClient extends events_1.EventEmitter {
312312
const progress = String(res.headers["x-progress"] || "").trim();
313313
const retryAfter = String(res.headers["retry-after"] || "").trim();
314314
const progressPct = parseInt(progress, 10);
315-
let retryAfterMSec = 1000;
315+
let retryAfterMSec = this.options.retryAfterMSec;
316316
if (retryAfter.match(/\d+/)) {
317317
retryAfterMSec = parseInt(retryAfter, 10) * 1000;
318318
}
319319
else {
320320
let d = new Date(retryAfter);
321321
retryAfterMSec = Math.ceil(d.getTime() - now);
322322
}
323-
const poolDelay = Math.min(Math.max(retryAfterMSec / 10, 1000), 10000);
323+
const poolDelay = Math.min(Math.max(retryAfterMSec, 100), 1000 * 60 * 60 * 24);
324324
Object.assign(status, {
325325
percentComplete: isNaN(progressPct) ? -1 : progressPct,
326326
nextCheckAfter: poolDelay,

config/defaults.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -284,5 +284,11 @@
284284
metadata: {
285285
// siteId: "localhost"
286286
}
287-
}
287+
},
288+
289+
/**
290+
* If the server does not provide `Retry-after` header use this number of
291+
* milliseconds before checking the status again
292+
*/
293+
retryAfterMSec: 200
288294
}

index.d.ts

+12
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ export declare namespace BulkDataClient {
211211
awsSecretAccessKey?: string
212212

213213
log?: LoggingOptions
214+
215+
/**
216+
* If the server does not provide `Retry-after` header use this number of
217+
* milliseconds before checking the status again
218+
*/
219+
retryAfterMSec?: number
214220
}
215221

216222
interface LoggingOptions
@@ -463,6 +469,12 @@ export declare namespace BulkDataClient {
463469
awsSecretAccessKey: string
464470

465471
log: LoggingOptions
472+
473+
/**
474+
* If the server does not provide `Retry-after` header use this number of
475+
* milliseconds before checking the status again
476+
*/
477+
retryAfterMSec: number
466478
}
467479

468480
interface JWK {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bulk-data-client",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"description": "",
55
"main": "built/app.js",
66
"engines": {

src/lib/BulkDataClient.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ class BulkDataClient extends EventEmitter
470470
const retryAfter = String(res.headers["retry-after"] || "").trim();
471471
const progressPct = parseInt(progress, 10);
472472

473-
let retryAfterMSec = 1000;
473+
let retryAfterMSec = this.options.retryAfterMSec;
474474
if (retryAfter.match(/\d+/)) {
475475
retryAfterMSec = parseInt(retryAfter, 10) * 1000
476476
} else {

0 commit comments

Comments
 (0)