Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
await Promise.all(rules.map(async (rule) => {
const queueUrl = rule.rule.value;
if (!(await sqsQueueExists(queueUrl))) return Promise.resolve();
const consumer = new Consumer({
queueUrl: queueUrl,
messageLimit,
timeLimit,
visibilityTimeout: rule.meta.visibilityTimeout,
deleteProcessedMessage: false
});
log.info(`processQueues for rule ${rule.name} and queue ${queueUrl}`);
return consumer.consume(dispatchFn.bind({ rule: rule }));
}));
}
async function handleEvent(event, dispatchFn, visibilityTimeout) {
const messageLimit = event.messageLimit || 1;
const timeLimit = get(event, 'timeLimit', 240);
if (!event.queueUrl) {
throw new Error('queueUrl is missing');
}
if (timeLimit <= 0) {
throw new Error('timeLimit must be greater than 0');
}
const consumer = new Consumer({
queueUrl: event.queueUrl,
messageLimit,
timeLimit,
visibilityTimeout
});
return consumer.consume(dispatchFn);
}