Skip to content

Commit d38c414

Browse files
authored
1.5.0 (#184)
1 parent 35d5407 commit d38c414

File tree

6 files changed

+16
-6
lines changed

6 files changed

+16
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ If you are importing data into a CouchDB database that already contains data, an
223223
* COUCH_OVERWRITE - overwrite existing document revisions with supplied data
224224
* COUCH_PARALLELISM - the maximum number of HTTP requests to have in flight at any one time (default: 1)
225225
* COUCH_MAX_WPS - the maximum number of write API calls to make per second (rate limiting) (default: 0 - no rate limiting)
226+
* COUCH_RETRY - whether to retry requests which yield a 429 response (default: false)
226227
227228
## Command-line parameters
228229
@@ -243,6 +244,7 @@ You can also configure `couchimport` and `couchexport` using command-line parame
243244
* `--parallelism` - the number of HTTP request to have in flight at any one time (default 1)
244245
* `--maxwps` - the maximum number of write API calls to make per second (default 0 - no rate limiting)
245246
* `--overwrite`/`-o` - overwrite existing document revisions with supplied data (default: false)
247+
* `--retry`/`-r` - whether to retry requests which yield a 429 response (default: false)
246248
247249
e.g.
248250

app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const importStream = function (rs, opts, callback) {
3030
headers.Authorization = 'Bearer ' + iamAccessToken
3131
}
3232

33-
const writer = require('./includes/writer.js')(opts.url, opts.database, opts.buffer, opts.parallelism, opts.ignorefields, opts.overwrite, opts.maxwps, headers)
33+
const writer = require('./includes/writer.js')(opts.url, opts.database, opts.buffer, opts.parallelism, opts.ignorefields, opts.overwrite, opts.maxwps, opts.retry, headers)
3434
const transformer = require('./includes/transformer.js')(opts.transform, opts.meta)
3535
const JSONStream = require('JSONStream')
3636
if (opts.type === 'jsonl') {

includes/args.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ const parse = function () {
7171
describe: 'whether to overwrite existing revisions with supplied data',
7272
default: process.env.COUCH_OVERWRITE ? process.env.COUCH_OVERWRITE : false
7373
})
74+
.option('retry', {
75+
alias: 'r',
76+
boolean: true,
77+
describe: 'whether to retry requests that yield a HTTP 429 response',
78+
default: process.env.COUCH_RETRY ? process.env.COUCH_RETRY : false
79+
})
7480
.argv
7581

7682
// load the transformation JavaScript

includes/writer.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const qrate = require('qrate')
33
const debug = require('debug')('couchimport')
44
const axios = require('axios').default
55

6-
module.exports = function (couchURL, couchDatabase, bufferSize, parallelism, ignoreFields, overwrite, maxwps, headers) {
6+
module.exports = function (couchURL, couchDatabase, bufferSize, parallelism, ignoreFields, overwrite, maxwps, retry, headers) {
77
const stream = require('stream')
88

99
let buffer = []
@@ -47,7 +47,6 @@ module.exports = function (couchURL, couchDatabase, bufferSize, parallelism, ign
4747
headers: headers
4848
}
4949
const response = await axios(req)
50-
5150
const existingData = response.data
5251
// make lookup table between id-->rev
5352
const lookup = {}
@@ -111,6 +110,9 @@ module.exports = function (couchURL, couchDatabase, bufferSize, parallelism, ign
111110
statusCode = e.response ? e.response.status : e.code
112111
failed = payload.docs.length
113112
writer.emit('writeerror', e)
113+
if (retry) {
114+
q.push(payload)
115+
}
114116
}
115117

116118
// log response code
@@ -122,7 +124,7 @@ module.exports = function (couchURL, couchDatabase, bufferSize, parallelism, ign
122124

123125
written += ok
124126
totalfailed += failed
125-
const status = { documents: ok, failed: failed, total: written, totalfailed: totalfailed, statusCodes: errorCodes, latency: latency}
127+
const status = { documents: ok, failed: failed, total: written, totalfailed: totalfailed, statusCodes: errorCodes, latency: latency }
126128
writer.emit('written', status)
127129
debug(JSON.stringify(status))
128130
}, parallelism, maxwps || undefined)

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "couchimport",
3-
"version": "1.4.6",
3+
"version": "1.5.0",
44
"description": "CouchImport - command-line helper to bulk import/export data from CSV/TSV",
55
"repository": "https://github.com/glynnbird/couchimport.git",
66
"keywords": [

0 commit comments

Comments
 (0)