Created
August 13, 2019 07:30
-
-
Save maatthc/94df52d257776cbec7830a23964202df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const BATCH_SIZE = 10 | |
const buildParamforSqsBatch = (products, queueUrl) => { | |
const entries = products.map(product => toOutputMessage(product)) | |
return { | |
Entries: entries, | |
QueueUrl: queueUrl | |
} | |
} | |
const emitUpdateEvent = (params) => { | |
return SQS().sendMessageBatch(params).promise() | |
} | |
exports.emitUpdateEventBatch = async (variantEvents) => { | |
let errors = [] | |
const res = await highland(variantEvents) | |
.batch(BATCH_SIZE) | |
.map(batch => buildParamforSqsBatch(batch, queueUrl)) // [{Entries, QueueUrl}] | |
.ratelimit(2000, 1000) // 2000 batched records per 1000ms | |
.flatMap(events => highland(emitUpdateEvent(events))) // highland([ Promise<>, ]) | |
.errors(error => errors.push(error)) | |
.collect() | |
.toPromise(Promise) | |
logger.info({ errors }, `Error on emitting records variant parent keycodes`) | |
return res | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment