src/service.js
/**
   * Writes the facilities into dynamodb.
   */
Writes the facilities into dynamodb.
Writes the facilities into dynamodb .
commit() {
    this.commitStarted = true;
    log.info(`Total facilities to be sent to DynamoDB: ${this.writeRequests.size}`);
    log.info(`Total facilities ignored: ${this.ignored}`);
    const BATCH_SIZE = 20;
    const WAIT_BETWEEN_BATCHES_MS = 500;
    const TOTAL_FACILITIES = this.writeRequests.size;
    let writeRequests = Array.from(this.writeRequests.values());
    let requestsSent = 0;
    async function resumeWriting() {
      const thisBatch = writeRequests.splice(0, BATCH_SIZE);
      if (thisBatch.length === 0) {
        return Promise.resolve();
      }
      await geoTableManager.batchWritePoints(thisBatch).promise();
      requestsSent += thisBatch.length;
      log.info(`Facilities sent to DynamoDB ${requestsSent++}/${TOTAL_FACILITIES}`);
      await new Promise(function(resolve) {
        setInterval(resolve, WAIT_BETWEEN_BATCHES_MS);
      });
      return resumeWriting();
    }
    return resumeWriting();
  }
commit ( ) { this . commitStarted = true ; log . info ( ` ${ this . writeRequests . size } ` ) ; log . info ( ` ${ this . ignored } ` ) ; const BATCH_SIZE = 20 ; const WAIT_BETWEEN_BATCHES_MS = 500 ; const TOTAL_FACILITIES = this . writeRequests . size ; let writeRequests = Array . from ( this . writeRequests . values ( ) ) ; let requestsSent = 0 ; async function resumeWriting ( ) { const thisBatch = writeRequests . splice ( 0 , BATCH_SIZE ) ; if ( thisBatch . length === 0 ) { return Promise . resolve ( ) ; } await geoTableManager . batchWritePoints ( thisBatch ) . promise ( ) ; requestsSent += thisBatch . length ; log . info ( ` ${ requestsSent ++ } ${ TOTAL_FACILITIES } ` ) ; await new Promise ( function ( resolve ) { setInterval ( resolve , WAIT_BETWEEN_BATCHES_MS ) ; } ) ; return resumeWriting ( ) ; } return resumeWriting ( ) ; }
Writes the facilities into dynamodb.
Writes the facilities into dynamodb .
// async function that will gradually send the facilities to dynamoDB // all facilities sent to dynamo // sends the facilities to dynamo // updates the count // sleeps // next batch // starts the process