Skip to content

Commit c2605ad

Browse files
committed
revert latest breaking amqp things
1 parent cc9e71f commit c2605ad

File tree

3 files changed

+14
-39
lines changed

3 files changed

+14
-39
lines changed

app/src/send.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ cache.on('put', function(key, val, ttl) { });
1111

1212
module.exports = {
1313

14-
sendHooks: function(conn, queue, data) {
14+
sendHooks: function(queue, data) {
1515

1616
if(queue === 'pokemon' || queue === 'raid' || queue === 'gym_details') {
1717
if(queue === 'pokemon'){
1818
if(cache.get(data.encounter_id) === undefined){
1919
cache.put(data.encounter_id, 'cached');
20-
sendRabbitMQ(conn, queue, data)
20+
sendRabbitMQ(queue, data)
2121
} else log.warn(`Encounter ${data.encounter_id} was sent again too fast`)
2222
}else if(queue === 'raid'){
2323
if(cache.get(data.gym_id) === undefined) {
2424
cache.put(data.gym_id, 'cachedGym');
25-
sendRabbitMQ(conn, queue, data)
25+
sendRabbitMQ(queue, data)
2626
} else log.warn(`Encounter ${data.gym_id} was sent again too fast`)
27-
} else sendRabbitMQ(conn, queue, data);
27+
} else sendRabbitMQ(queue, data);
2828
}
2929
},
3030
sendTestHook: function(queue, data, callback) {
@@ -41,11 +41,14 @@ module.exports = {
4141
conn.close();
4242
}, 500);
4343
});
44+
4445
}
46+
4547
};
4648

47-
function sendRabbitMQ(conn, queue, data){
49+
function sendRabbitMQ(queue, data){
4850

51+
amqp.connect(config.rabbit.conn, function (err, conn) {
4952
conn.createChannel(function (err, ch) {
5053
let q = queue;
5154
ch.assertQueue(q, {durable: false});
@@ -55,4 +58,5 @@ function sendRabbitMQ(conn, queue, data){
5558
setTimeout(function () {
5659
conn.close();
5760
}, 500);
61+
});
5862
}

app/src/server.js

+5-15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const log = require("./logger");
55
const sender = require("./send");
66
const query = require('./sql/queries');
77
const migrator = require('./sql/migration/migrator');
8-
const amqpc = require('./util/helpers/AMQPConnHelper');
98

109
const opts = {
1110
schema: {
@@ -20,22 +19,20 @@ const opts = {
2019
}
2120
};
2221

23-
let connection = undefined;
24-
2522
//webserver healthcheck
2623

27-
fastify.get('/', opts, function (request, reply){
28-
reply.type('application/json').code(200);
29-
reply.send({ Webserver: 'Happy' });
30-
});
24+
fastify.get('/', opts, function (request, reply){
25+
reply.type('application/json').code(200);
26+
reply.send({ Webserver: 'Happy' });
27+
});
3128

3229
//receive hooks
3330

3431

3532
fastify.post('/', opts, function(request, reply){
3633
request.body.forEach(function(hook){
3734
log.debug(prettyjson.render(hook));
38-
sender.sendHooks(connection, hook.type, hook.message);
35+
sender.sendHooks(hook.type, hook.message);
3936
});
4037
reply.type('application/json').code(200);
4138
reply.send({ Webserver: 'Happy' });
@@ -44,12 +41,6 @@ fastify.post('/', opts, function(request, reply){
4441

4542
fastify.listen(config.general.port, config.general.host, function (err) {
4643
if (err) throw err;
47-
amqpc.connection(function(err, conn){
48-
if(err){ log.error(`AMQP Not happy, please check bunnywabbit ${err}`);
49-
throw err;
50-
}
51-
connection = conn;
52-
});
5344
log.info(`Poracle started on ${fastify.server.address().address}:${fastify.server.address().port}`)
5445
});
5546

@@ -61,4 +52,3 @@ query.countQuery('TABLE_NAME','information_schema.tables','table_schema',config.
6152
migrator.migration1()
6253
}
6354
});
64-

app/src/util/helpers/AMQPConnHelper.js

-19
This file was deleted.

0 commit comments

Comments
 (0)