Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding some singleton redis connections.

  • Loading branch information...
commit 7530cd883afc5f5e2f432010f08cf374c3779499 1 parent a2fc161
@simonwex simonwex authored
View
7 app/feeds/bugzilla.js
@@ -11,7 +11,7 @@ logger = require('../../lib/logger'),
config = require('../../lib/configuration'),
https = require('https'),
mysql = require('mysql').createClient(config.get('mysql')),
-redis = require('../../lib/redis')();
+redis = require('../../lib/redis').io;
var users = [];
@@ -37,7 +37,7 @@ function getHttpOptions(email){
function getUsers(callback){
logger.verbose('Retrieving users for bugzilla polling...');
- mysql.query('SELECT id, email FROM users ORDER BY id DESC', function(err, result){
+ mysql.query('SELECT id, email FROM users ORDER BY id', function(err, result){
if (err){
logger.error("Error retrieving users for bugzilla: " + err);
}
@@ -45,6 +45,7 @@ function getUsers(callback){
users.push({id: result[i].id, email: result[i].email});
}
+
if (typeof(callback) == 'function'){
callback();
}
@@ -78,8 +79,6 @@ function createStory(user, bug){
if (bug.creator)
people = [bug.creator.real_name];
- console.log(bug);
-
var story = {
id: 'bugzilla:' + bug.id + ":" + bug.last_change_time,
// TODO: Get email from bugzilla username (creator":{"real_name":"Shane Caraveo (:mixedpuppy)","name":"mixedpuppy"})
View
9 app/feeds/daemon.js
@@ -14,11 +14,13 @@ config = require('../../lib/configuration'),
deduper = new (require('./deduper'))(maxStoryAge),
FeedParser = require('feedparser'),
mysql = require('mysql').createClient(config.get('mysql')),
-redis = require('../../lib/redis')();
+redis = require('../../lib/redis').io;
var subscriptions = {}; // {<url>: [<user.id>, ...], ...
var timers = {};
+
+
function schedule(url, delay){
if (!delay)
delay = (30).seconds();
@@ -45,7 +47,6 @@ function scrape(url){
}
else{
for (var i in articles){
-
var story = {
id: articles[i].guid,
people: articles[i].author,
@@ -54,7 +55,6 @@ function scrape(url){
pubdate: articles[i].pubdate,
image: articles[i].image
};
-
if (((new Date() - Date.parse(story.pubdate) < maxStoryAge) && deduper.hasntHeardOf(story.id))) {
deduper.add(story.id);
@@ -96,13 +96,14 @@ function reloadUrls(){
}
}
else{
- logger.error("Error initializing RSS Scraper: " + err + "\n\nExiting.");
+ logger.error("Error loading URLs to scrape in Feed Daemon: " + err + "\n\nExiting.");
process.exit(1);
}
}
);
}
+
var reloadInterval = setInterval(reloadUrls, (10).minutes());
reloadUrls();
View
17 app/http/controllers/profile.js
@@ -4,9 +4,10 @@
const
config = require('../../../lib/configuration'),
-uuid = require('node-uuid'),
+uuid = require('node-uuid'),
logger = require('../../../lib/logger'),
-createRedisClient = require('../../../lib/redis');
+mysql = require('mysql').createClient(config.get('mysql')),
+Redis = require('../../../lib/redis');
/*
* Get for index
@@ -38,31 +39,33 @@ exports.nick = {
post: function(req, resp){
// Look up the other details from the nick.
var responseQueue = "irc-resp:" + uuid.v1();
- var redis = createRedisClient();
+ var redis = Redis.new();
redis.lpush("irc:whois", JSON.stringify([req.body.user.nick, responseQueue]));
resp.header('Content-Type', 'application/json');
// Wait on reponse queue for 10 secs(max)
- redis.brpop(responseQueue, 10, function(err, data){
+ redis.brpop(responseQueue, 2, function(err, data){
+ redis.quit();
+
req.user.nick = req.body.user.nick;
if (data) {
var whois = JSON.parse(data[1]);
-
+
req.user.realName = whois.realname;
resp.send(JSON.stringify({realName: req.user.realName, networks: whois.channels}));
}
else {
- resp.send(JSON.stringify({realName: '', networks: [], error: "No response received."}), {status: 500});
+ resp.send(JSON.stringify({realName: '', networks: [], error: "No response received."}));
}
req.user.save(function(err){
if (err)
logger.error(err);
});
- redis.quit();
+
});
}
};
View
8 app/http/controllers/social.js
@@ -3,10 +3,10 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
const
-config = require('../../../lib/configuration'),
-mysql = require('mysql').createClient(config.get('mysql')),
-createRedisClient = require('../../../lib/redis'),
-logger = require('../../../lib/logger');
+config = require('../../../lib/configuration'),
+mysql = require('mysql').createClient(config.get('mysql')),
+redis = require('../../../lib/redis').pub,
+logger = require('../../../lib/logger');
/*
* GET home page.
View
1  app/http/server.js
@@ -13,7 +13,6 @@ logger = require('../../lib/logger'),
passport = require('passport'),
util = require('util'),
application = require('./controllers/application'),
-redis = require('../../lib/redis')(),
socket = require('./socket'),
connect = require('connect'),
RedisStore = require('connect-redis')(connect),
View
2  app/http/socket.js
@@ -12,7 +12,7 @@ utils = require('util'),
WebSocketServer = require('websocket').server,
sio = require('socket.io'),
uuid = require('node-uuid'),
-createRedisClient = require('../../lib/redis'),
+createRedisClient = require('../../lib/redis').new,
pubsubRedis = createRedisClient(),
parseCookie = require('connect').utils.parseCookie,
logger = require('../../lib/logger'),
View
24 app/irc/bot-listeners.js
@@ -3,12 +3,12 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
var
-config = require('../../lib/configuration'),
-uuid = require('node-uuid'),
-redis = require('../../lib/redis')(),
-BotUtils = require('./bot-utils'),
-botDB = require('./bot-mysql'),
-logger = require('../../lib/logger');
+config = require('../../lib/configuration'),
+uuid = require('node-uuid')
+redis = require('../../lib/redis').pub,
+BotUtils = require('./bot-utils'),
+botDB = require('./bot-mysql'),
+logger = require('../../lib/logger');
module.exports = function(bot){
var self = this;
@@ -83,9 +83,21 @@ module.exports = function(bot){
});
};
+ this.channelListReturned = function(channels){
+ botDB.updateChannelList(channels);
+ };
+
this.botRegistered = function(){
bot.state = "registered";
+ bot.client.list();
+
+ setInterval(
+ function(){
+ bot.client.list();
+ }, (1).minute
+ );
+
// We're registered, now we wait until the bot has joined #motown
bot.client.once('join', self.botJoinedMotown);
};
View
6 app/irc/bot-worker.js
@@ -7,12 +7,12 @@ config = require('../../lib/configuration'),
mysql = require('mysql').createClient(config.get('mysql')),
BotUtils = require('./bot-utils'),
Redis = require('../../lib/redis'),
+redis = Redis.io,
logger = require('../../lib/logger');
function Worker(bot){
this.bot = bot;
- this.workerRedis = new Redis();
- this.redis = new Redis();
+ this.workerRedis = Redis.new();
var self = this;
this.bot.once('operational', function(){self.beAGoodLittleWorker()});
}
@@ -32,7 +32,7 @@ Worker.prototype.beAGoodLittleWorker = function(){
var responseQueue = args.pop();
args.push(function(resp){
- self.redis.lpush(responseQueue, JSON.stringify(resp));
+ redis.lpush(responseQueue, JSON.stringify(resp));
});
switch(cmd){
View
8 lib/redis.js
@@ -6,7 +6,7 @@ const config = require('./configuration').get('redis');
var redis = require('redis');
-module.exports = function(){
+function createClient(){
redisClient = redis.createClient(config.port, config.host);
redisClient.debug_mode = false;
@@ -17,3 +17,9 @@ module.exports = function(){
}
return redisClient;
}
+
+module.exports = {
+ io: createClient(),
+ pub: createClient(),
+ 'new': createClient
+}
Please sign in to comment.
Something went wrong with that request. Please try again.