@@ -15,11 +15,11 @@ const MIGRATION_SEED_CONCURRENCY = 5;
15
15
/**
16
16
* Writes a batch chunk of migration seeds to DynamoDB. DynamoDB has a limit on the number of
17
17
* items that may be written in a batch operation.
18
- * @param {DynamoDocumentClient } dynamodb The DynamoDB Document client
18
+ * @param {function } dynamodbWriteFunction The DynamoDB DocumentClient.batchWrite or DynamoDB.batchWriteItem function
19
19
* @param {string } tableName The table name being written to
20
20
* @param {any[] } seeds The migration seeds being written to the table
21
21
*/
22
- function writeSeedBatch ( dynamodb , tableName , seeds ) {
22
+ function writeSeedBatch ( dynamodbWriteFunction , tableName , seeds ) {
23
23
const params = {
24
24
RequestItems : {
25
25
[ tableName ] : seeds . map ( ( seed ) => ( {
@@ -34,7 +34,7 @@ function writeSeedBatch(dynamodb, tableName, seeds) {
34
34
// again a few times in case the Database resources are in the middle of provisioning.
35
35
let interval = 0 ;
36
36
function execute ( interval ) {
37
- setTimeout ( ( ) => dynamodb . batchWrite ( params , ( err ) => {
37
+ setTimeout ( ( ) => dynamodbWriteFunction ( params , ( err ) => {
38
38
if ( err ) {
39
39
if ( err . code === "ResourceNotFoundException" && interval <= 5000 ) {
40
40
execute ( interval + 1000 ) ;
@@ -52,13 +52,13 @@ function writeSeedBatch(dynamodb, tableName, seeds) {
52
52
53
53
/**
54
54
* Writes a seed corpus to the given database table
55
- * @param {DocumentClient } dynamodb The DynamoDB document instance
55
+ * @param {function } dynamodbWriteFunction The DynamoDB DocumentClient.batchWrite or DynamoDB.batchWriteItem function
56
56
* @param {string } tableName The table name
57
57
* @param {any[] } seeds The seed values
58
58
*/
59
- function writeSeeds ( dynamodb , tableName , seeds ) {
60
- if ( ! dynamodb ) {
61
- throw new Error ( "dynamodb argument must be provided" ) ;
59
+ function writeSeeds ( dynamodbWriteFunction , tableName , seeds ) {
60
+ if ( ! dynamodbWriteFunction ) {
61
+ throw new Error ( "dynamodbWriteFunction argument must be provided" ) ;
62
62
}
63
63
if ( ! tableName ) {
64
64
throw new Error ( "table name argument must be provided" ) ;
@@ -71,7 +71,7 @@ function writeSeeds(dynamodb, tableName, seeds) {
71
71
const seedChunks = _ . chunk ( seeds , MAX_MIGRATION_CHUNK ) ;
72
72
return BbPromise . map (
73
73
seedChunks ,
74
- ( chunk ) => writeSeedBatch ( dynamodb , tableName , chunk ) ,
74
+ ( chunk ) => writeSeedBatch ( dynamodbWriteFunction , tableName , chunk ) ,
75
75
{ concurrency : MIGRATION_SEED_CONCURRENCY }
76
76
)
77
77
. then ( ( ) => console . log ( "Seed running complete for table: " + tableName ) ) ;
0 commit comments