Created
October 3, 2016 13:56
-
-
Save mauriciofs/9a7d52da0290d3eff02903eb2b14e9e9 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
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