forked from mher/node-celery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protocol.js
56 lines (47 loc) · 923 Bytes
/
protocol.js
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
51
52
53
54
55
56
var uuid = require('uuid');
var fields = [
'task',
'id',
'args',
'kwargs',
'retries',
'eta',
'expires',
'queue',
'taskset',
'chord',
'utc',
'callbacks',
'errbacks',
'timeouts',
'priority',
];
function formatDate(date) {
return new Date(date).toISOString();
}
function createMessage(task, args, kwargs, options, id) {
args = args || [];
kwargs = kwargs || {};
var message = {
task: task,
args: args,
kwargs: kwargs,
};
message.id = id || uuid.v4();
for (var o in options) {
if (options.hasOwnProperty(o)) {
if (fields.indexOf(o) === -1) {
throw 'invalid option: ' + o;
}
message[o] = options[o];
}
}
if (message.eta) {
message.eta = formatDate(message.eta);
}
if (message.expires) {
message.expires = formatDate(message.expires);
}
return JSON.stringify(message);
}
exports.createMessage = createMessage;