-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmail-queue.js
More file actions
44 lines (36 loc) · 994 Bytes
/
mail-queue.js
File metadata and controls
44 lines (36 loc) · 994 Bytes
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
var Q = require('q');
var ironMq = require('iron_mq');
var queue;
exports.configure = function (options) {
var imq = new ironMq.Client({
token: options.token,
project_id: options.projectId
});
queue = imq.queue('Mail');
};
exports.post = function (payload) {
if (!queue) {
console.error('IronMQ project_id and token are not configured');
return;
}
var json = JSON.stringify(payload);
console.log('mail-queue: POST', json);
return Q.nbind(queue.post, queue)(json).fail(function (err) {
console.error('IronMQ error:', err.message, json);
throw err;
});
};
exports.get = function () {
return Q.nbind(queue.get, queue)({
n: 1 // Note that the response is an array if n > 1
}).then(function (response) {
response.body = JSON.parse(response.body);
return response;
});
};
exports.del = function (messageId) {
return Q.nbind(queue.del, queue)(messageId);
};
exports.clear = function () {
return Q.nbind(queue.clear, queue)();
};