forked from cbmsc-diti/mogi-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconsumer.js
44 lines (39 loc) · 1.39 KB
/
consumer.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
/**
* Module dependencies.
*/
var db = require('./lib/db')
, config = require('./lib/config')
, rabbitmq = require('./lib/rabbitmq')
, storage = require('./lib/videos/storage')
, crypto = require('./lib/crypto');
var option = {force: false};
db.sequelize.sync(option).then(function () {
crypto.crypto_init(function () {
rabbitmq.init(function () {
rabbitmq.connection().queue('copcast-q', function(q) {
console.log('Queue ' + q.name + ' is open');
q.bind(rabbitmq.exchange(), 'copcast-k', function() {
console.log('Consumer ready. Maximum parallel executions: '+config.rabbitmq.prefetchCount);
q.subscribe({ack: true, prefetchCount: config.rabbitmq.prefetchCount}, function (message, headers, deliveryInfo, ack) {
try{
console.log('Begining ingestion: '+message.path);
storage.ingestVideo(message.path, message.user.id, message.date, function(code, err) {
if (err)
console.log(err);
else
console.log(message.path+' file ingested.');
ack.acknowledge();
});
} catch(err) {
console.log('Error ingesting video: '+err);
}
});
});
});
});
});
}).catch(function(err) {
console.log('Failed to access the database.');
console.log(err);
process.exit(-1);
});