Skip to content

Instantly share code, notes, and snippets.

@mauriciofs
Created October 3, 2016 13:56
Show Gist options
  • Save mauriciofs/9a7d52da0290d3eff02903eb2b14e9e9 to your computer and use it in GitHub Desktop.
Save mauriciofs/9a7d52da0290d3eff02903eb2b14e9e9 to your computer and use it in GitHub Desktop.
receive(){
//Arrow function to not change this context
return new Promise((resolve, reject) => {
let params = {
QueueUrl: this.url,
WaitTimeSeconds: this.waitTimeSeconds,
MaxNumberOfMessages: this.maxNumberOfMessages,
MessageAttributeNames: [
'reprocess'
]
};
console.log(`(${this.url}) GETTING MESSAGES...`);
this.SQS.receiveMessage(params, (err, data) => {
if(err) return reject(err);
console.log('Message', util.inspect(data, false, null));
if (data !== null && data.Messages && data.Messages.length > 0) {
console.log('RESOLVING...');
return resolve(data);
}
//Try again
this.receive();
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment