Comparing version 0.3.0 to 0.3.1
@@ -7,3 +7,3 @@ var _ = require('underscore'); | ||
_(dyno).extend(dyno.config.dynamo); | ||
_(dyno).extend(require('./lib/item')); | ||
_(dyno).extend(_(require('./lib/item')).omit('_response')); | ||
_(dyno).extend(require('./lib/query')); | ||
@@ -10,0 +10,0 @@ _(dyno).extend(require('./lib/scan')); |
@@ -31,3 +31,3 @@ var util = require('util'); | ||
}; | ||
config.dynamo.putItem(params, cb); | ||
config.dynamo.putItem(params, items._response(config.dynamo.putItem, params, opts, cb)); | ||
}; | ||
@@ -49,1 +49,25 @@ | ||
}; | ||
items._response = function(func, params, opts, cb) { | ||
var attempts = 0; | ||
var retry = function() { | ||
func.bind(config.dynamo)(params, handleResp); | ||
}; | ||
var handleResp = function(err, resp) { | ||
if(!opts.errors || !err) { | ||
return cb(err, resp); | ||
} | ||
if (err.code = "ProvisionedThroughputExceededException") { | ||
if(_.isNumber(opts.errors.throughput) && attempts <= opts.errors.throughput){ | ||
attempts++; | ||
setTimeout(retry, 100 * attempts * attempts); | ||
} else { | ||
cb(err, resp); | ||
} | ||
} | ||
} | ||
return handleResp; | ||
}; |
{ | ||
"name": "dyno", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Simple DynamoDB client", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -247,1 +247,35 @@ var test = require('tap').test; | ||
test('teardown', s.teardown); | ||
test('setup', s.setup()); | ||
test('setup table', s.setupTable); | ||
test('put error, throughput', function(t) { | ||
var items = require('../lib/item'); | ||
var types = require('../lib/types'); | ||
var config = require('../lib/config')(); | ||
var item = types.toDynamoTypes({id: 'yo', range: 5}); | ||
var params = { | ||
TableName: config.table, | ||
Item: item | ||
}; | ||
var handleResp = items._response( | ||
config.dynamo.putItem, | ||
params, | ||
{errors:{throughput:10}}, | ||
itemResp | ||
); | ||
// Send it a fake bad response. | ||
handleResp({code:'ProvisionedThroughputExceededException'}, {}) | ||
function itemResp(err, resp) { | ||
t.equal(err, null); | ||
t.deepEqual(resp, {}); | ||
dyno.getItem(item, getItem); | ||
} | ||
function getItem(err, resp) { | ||
t.equal(err, null); | ||
t.deepEqual(resp, {Item:{id: 'yo', range: 5}}); | ||
t.end(); | ||
} | ||
}); | ||
test('teardown', s.teardown); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28200
809