-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample-poll-loop.js
More file actions
50 lines (39 loc) · 1.24 KB
/
sample-poll-loop.js
File metadata and controls
50 lines (39 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(async function() {
let SesInboundPoller = await require('./ses-inbound-relay').init();
let smtpConfig = {
host: 'localhost',
port: 25
};
var poller = new SesInboundPoller("us-east-1", "https://sqs.us-east-1.amazonaws.com/974018730731/johnnyc-lol-inbound-sns-notifications", smtpConfig);
function handleError() {
console.log("Encountered an error, backing off.");
console.log(err, err.stack);
setTimeout(doPoll, 5000);
}
function doPoll() {
poller.poll(function (err, msgMeta, rawMsg, receiptHandle) {
if (err) {
handleError(err);
return;
}
if (msgMeta == null) {
setTimeout(doPoll, 10);
return;
}
poller.relay(msgMeta, rawMsg, function (err) {
if (err) {
handleError(err);
return;
}
poller.delete(receiptHandle, function (err) {
if (err) {
handleError(err);
return;
}
setTimeout(doPoll, 10);
});
});
});
}
doPoll();
})();