-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.js
More file actions
55 lines (46 loc) · 1.31 KB
/
Copy pathparser.js
File metadata and controls
55 lines (46 loc) · 1.31 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
51
52
53
54
55
'use strict';
const connection = require('./helpers/connection');
const parser = require('./helpers/parser');
const amqp = require('amqplib/callback_api');
const debug = require('debug')('http');
let url;
let mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/apartment_db', {
server: {
socketOptions: {
socketTimeoutMS: 0,
connectTimeoutMS: 0
}
}
});
amqp.connect('amqp://localhost', function (err, conn) {
if (conn != undefined) {
conn.createChannel(function (err, ch) {
let q = 'links';
ch.prefetch(1);
ch.assertQueue(q, {durable: false});
debug(" [*] Waiting for messages in %s. To exit press CTRL+C", q);
ch.consume(q, function (msg) {
console.log(" [x] Received %s", msg.content.toString());
url = msg.content.toString();
connection.connect('https://www.propertyfinder.com.lb' + url)
.then(function (data) {
debug('in 1');
if (data != null) {
return parser.getAllInformations(data);
} else {
throw msg;
}
})
.then(function () {
debug('finish');
ch.ack(msg);
})
.catch(function (msg) {
debug('error');
ch.reject(msg, true);
});
}, {noAck: false});
});
}
});