Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
RedisStore + Socket.io not working together. Code works fine on single core, as soon as worker threads are added messages are lost. Sub/Pub is happening but messages not passed to connected sockets. Vanilla Redis install running on localhost and default port. Socket.io version 9.10, redis node 8.15 ubuntu 11.04 redis 2.7.6. Error seems to be tha…
/* OOPA ROOPA WEB APP
** Author : Kenley Tomlin
** Email : kenleytomlin@gmail.com
** Date : 2012/12/07 (latest update)
**
** Version 0.0.3 - Added redisStore to socket io's config. Scaling the app to work with multiple cores.
** Version 0.0.2 - Removed https server from node, nginx now serves certificates and proxies to node.
** Version 0.0.1 - Added a redirect app that catches the missing 'www.' from the url and redirects the user to http://www.ooparoopa.com
*/
var fs = require('fs');
var http = require('http');
var express = require('express');
var io = require('socket.io');
var os = require('os');
var cluster = require('cluster');
var workerArr = {}; //Object containing worker processes.
var rssWarn = (250 * 1024 * 1024); //250 mbs, used to check that a single process isn't hogging too much ram
if(cluster.isMaster)
{
for(var i = 0;i < 2; i++)
{
createWorker(); //This function creates workers for us.
}
setInterval(function () {
var now = new Date().getTime();
for(id in workerArr)
{
if(workerArr.hasOwnProperty(id) && workerArr[id].lastCb + 5000 < now)
{
console.log('Long running worker ' + id + ' killed');
workerArr[id].worker.destroy();
delete workerArr[id];
createWorker();
}
}
},1000);
}
else
{
//WORKER PROCESSES - MAIN APPLICATION
var app = express();
var httpServer = http.createServer(app).listen(8888);
io = io.listen(httpServer);
//We need the database object and connection to pass to the virtual host apps
var Database = require('./lib/Database');
var db = new Database();
db.connect('mongodb://localhost/ooparoopa');
//The virtual host apps. One for the admin one for the frontend site
var adminSiteApp = require('./adminsite/app')(db);
var mallSiteApp = require('./mallsite/app')(db,io);
app.use(express.vhost('testadmin.ooparoopa.com', adminSiteApp))
.use(express.vhost('testweb.ooparoopa.com', mallSiteApp));
console.log('Server Started On Port : 8888');
setInterval(function report() {
process.send({ cmd: 'reportMem', memory : process.memoryUsage(), process : process.pid });
}, 1000);
}
function createWorker () {
var worker = cluster.fork();
console.log('Created worker: ' + worker.process.pid);
//Allow some boot time
workerArr[worker.process.pid] = { worker: worker, lastCb : new Date().getTime() - 1000 };
worker.on('message',function (m) {
if(m.cmd === 'reportMem')
{
workerArr[m.process].lastCb = new Date().getTime();
if(m.memory.rss > rssWarn)
{
console.log('Worker ' + m.process + ' using too much memory');
}
}
});
}
module.exports = function(db,io) {
var express = require('express');
var app = express();
//Load config
var config = require('./Config')(app,express,io);
//Static pages routes
var MallStaticPages = require('./lib/MallStaticPages');
var mallStaticPages = new MallStaticPages();
mallStaticPages.initPages(app,db);
//Sign up pages routes and logic
var MallSignUpPages = require('./lib/MallSignUpPages');
var mallSignUpPages = new MallSignUpPages();
mallSignUpPages.initPages(app,db);
var MallAdminPages = require('./lib/MallAdminPages');
var mallAdminPages = new MallAdminPages();
mallAdminPages.initPages(app,db);
var PointsManager = require('./lib/PointsManager');
var pointsManager = new PointsManager();
pointsManager.init(app,db);
var ReservationPages = require('./lib/ReservationPages');
var reservationPages = new ReservationPages();
reservationPages.initPages(app,db,io);
var MallCreateGame = require('./lib/MallCreateGame');
var mallCreateGame = new MallCreateGame();
mallCreateGame.initPages(app,db);
var MallPaymentPages = require('./lib/MallPaymentPages');
var mallPaymentPages = new MallPaymentPages();
mallPaymentPages.initPages(app,db);
var MallGameFinishedMail = require('./lib/MallGameFinishedMail');
var mallGameFinishedMail = new MallGameFinishedMail();
mallGameFinishedMail.initQueue(db);
return app;
}
var mongoStore = require('session-mongoose');
var connect = require('../node_modules/express/node_modules/connect');
var redisStore = require('socket.io/lib/stores/redis');
var redis = require('redis');
var pub = redis.createClient({ host : 'localhost', port :'6379' });
var sub = redis.createClient({ host : 'localhost', port : '6379'});
var client = redis.createClient({ host : 'localhost', port : '6379'});
var cookie = require('cookie');
var store;
module.exports = function(app,express,io){
app.configure(function(){
var mongooseSessionStore = new mongoStore({
url: "mongodb://localhost/ooparoopa",
interval: 240000
});
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser({keepExtensions : true, uploadDir : __dirname + '/tempuploads'}));
app.use(express.methodOverride());
app.use(express.compress());
app.use(express.static( __dirname +'/public'));
app.use(express.logger());
app.use(express.cookieParser());
app.use(connect.limit('5mb'));
app.use(express.session( { cookie: {maxAge: 1800000}, key : 'express.sid', store: store = mongooseSessionStore, secret: "ooparoopamustmakedollars"} ) );
app.use(app.router);
app.enable('trust-proxy'); //Trust NGINX proxies
});
app.configure('development',function(){
app.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
io.configure(function () {
io.enable('browser client minification');
io.enable('browser client etag');
io.enable('browser client gzip');
io.set('log level', 3);
io.set('transports', ['xhr-polling']);
io.set('polling duration',10);
io.set('heartbeat interval', 20);
io.set('heartbeat timeout', 60);
io.set('store',new redisStore({
redis : redis,
redisPub : pub,
redisSub : sub,
redisClient : client
}));
io.set('authorization', function (data,accept) {
console.log(data)
if(data.headers.cookie) {
data.cookie = connect.utils.parseSignedCookies(cookie.parse(decodeURIComponent(data.headers.cookie)),"ooparoopamustmakedollars");
data.sessionID = data.cookie['express.sid'];
store.load(data.sessionID, function (err,session) {
console.log(session);
if (err || !session) return accept('Error',false);
data.session = session;
return accept(null,true);
});
}
else
{
return accept('No Cookie Transmitted', false);
}
});
});
app.use(function (req,res,next) { //404 page handler
if(err.status == 404)
{
res.render('error/error404',{
title : 'Error 404',
pageCategory : 'Error404',
pageName : 'error404',
});
}
next();
});
app.use(function (err,req,res,next) {
if(err.status == 505)
{
res.render('error/error505',{
title : 'Error 505',
pageCategory : 'Error 505',
pageName : 'error505',
});
}
next();
});
app.use(function (err,req,res,next) {
if(err.status == 413) //Entity too large error handling
{
if(req.route.path === '/mall/createGame/finalize' || req.route.path === '/mall/editGame/finalize')
{
res.json({ success : false, msg : 'Post parameters exceed allowed length' });
}
else if(
req.route.path === '/mall/createGame/imageUpload'
|| req.route.path === '/mall/editGame/imageUpload'
|| req.path.route === '/mall/editGame/thumbUpload'
|| req.path.route === '/mall/createGame/thumbUpload') //Handle image uploads that are too large
{
res.status(err.status).send(); //Set the response of the response to 413
}
}
next();
});
};
var CheckLogin = require('../../lib/Tools/CheckLogin');
var Schedule = require('../../lib/Schedule');
var ResMall = require('./Res/ResMall');
var selectedSlots = [];
var getKeys = function(array) {
var keys = [];
for(var key in array)
{
keys.push(key);
}
return keys;
}
var ReservationPages = module.exports = function () {};
ReservationPages.prototype = {
db : null,
io : null,
initPages : function (app,db,io) {
this.db = db;
this.io = io;
var self = this;
//ROUTING
//RESERVATION PAGE ROUTE
app.get('/mall/reservation', function (req,res) { self.reservationPage (req,res); } );
//SOCKET IO EVENTS
//CONNECTION
io.of('/mall/reservation').on('connection', function (socket) { self.reservationConnect (socket); } );
},
checkLogin : function (req,res) {
if (req.session && req.session.loggedIn === true)
return true;
res.redirect('/login');
return false;
},
reservationPage : function (req,res) {
if(!CheckLogin.checkLoginMall(req,res)) return;
var Settings = this.db.model('Settings');
Settings.find().select('startDay startHour lastDay lastHour cancelDay cancelHour slotPrice slotDiscount').exec(function (err,settingData) {
if(err)
{
}
else
{
var settingData = settingData[0]; //Make it easier to work with this
var midnightGameDay = new Date(Schedule.midnightGameDay(settingData['startDay']));
var startDay = new Date(midnightGameDay.getTime() + (settingData.startHour * Schedule.HOUR_IN_MILLISECONDS)); //The time and date that the first game can be reserved
var lastDay = new Date(midnightGameDay.getTime() + (settingData.lastHour * Schedule.HOUR_IN_MILLISECONDS) + (settingData.lastDay * Schedule.DAY_IN_MILLISECONDS)); //The time and date that the last game be reserved today.
var slotP = []; //this will contain the prices of each slot per hour.
var y = 0;
for(var x = 0;x < settingData.slotPrice.length;x++)
{
if(settingData.slotPrice[x].finishDate.getTime() >= startDay.getTime())
{
console.log('x');
console.log(x);
slotP.push(settingData.slotPrice[x]);
}
}
res.render('mall/reservation', {
title : '경기 개최하기',
pageCategory : 'Game Slot Reservation',
pageName : 'reservation',
loginStatus : req.session.loggedIn,
data : { startDay : startDay.toString(), lastDay : lastDay.toString(), cancelDay : settingData.cancelDay, cancelHour : settingData.cancelHour, slotPrice : slotP, slotDiscount : settingData.slotDiscount }
});
}
});
},
reservationConnect : function (socket) {
var Reservation = this.db.model('Reservation');
var Game = this.db.model('Game');
var Settings = this.db.model('Settings');
var Transaction = this.db.model('Transaction');
var Mall = this.db.model('Mall');
var self = this;
//console.log('socket');
//console.log(socket);
console.log(socket.handshake.session);
//socket.handshake.session.touch().save();
socket.join(socket.handshake.session._id);
if(socket.handshake.session && socket.handshake.session.loggedIn === true)
{
console.log('connectionOk');
self.io.sockets.in(socket.handshake.session._id).emit('connectionOk');
socket.on('selectDay', function (data) {
var selectedSlotDate = new Date(data.day);
Game.find().select('closeTime').where('mallId').ne(socket.handshake.session._id).where('closeTime').gte( selectedSlotDate.getTime() - Schedule.HOUR_IN_MILLISECONDS).lte(selectedSlotDate.getTime() + (Schedule.HOUR_IN_MILLISECONDS * 24)).exec(function (err,gameData) {
if(err)
{
console.log(err);
}
else
{
var x = 0;
var gameD = [];
gameData.forEach(function (game) {
var closeTime = game.closeTime.toString();
gameD[x] = closeTime;
x++;
});
self.io.sockets.in(socket.handshake.session._id).emit('gameList',{ data : gameD });
}
});
Game.find().select('closeTime').where('mallId').equals(socket.handshake.session._id).where('closeTime').gte(selectedSlotDate.getTime() - Schedule.HOUR_IN_MILLISECONDS).lte(selectedSlotDate.getTime() + (Schedule.HOUR_IN_MILLISECONDS * 24)).exec(function (err,myGameData) {
if(err)
{
console.log(err);
}
else
{
var x =0;
var myGameD = [];
myGameData.forEach(function (game) {
var closeTime = game.closeTime.toString();
var closeTime = closeTime;
myGameD[x] = closeTime;
x++;
});
self.io.sockets.in(socket.handshake.session._id).emit('myGameList', { data : myGameD });
}
});
Reservation.find().select('closeTime').where('mallId').ne(socket.handshake.session._id).where('closeTime').gte(selectedSlotDate.getTime() - Schedule.HOUR_IN_MILLISECONDS).where('closeTime').lte(selectedSlotDate.getTime() + (Schedule.HOUR_IN_MILLISECONDS * 24)).exec(function (err,reservationData) {
if(err)
{
console.log(err);
}
else
{
var x = 0;
var reservationD = [];
reservationData.forEach(function (game) {
var closeTime = game.closeTime.toString();
reservationD[x] = closeTime;
x++;
});
self.io.sockets.in(socket.handshake.session._id).emit('reserveList', { data : reservationD });
}
});
Reservation.find().select('closeTime').where('mallId').equals(socket.handshake.session._id).where('closeTime').gte(selectedSlotDate.getTime() - Schedule.HOUR_IN_MILLISECONDS).where('closeTime').lte(selectedSlotDate.getTime() + (Schedule.HOUR_IN_MILLISECONDS * 24)).exec(function (err,myReservationData) {
if(err)
{
console.log(err);
}
else
{
var x = 0;
var myReservationD = [];
myReservationData.forEach(function (game) { //For IE as it doesn't support ISO date strings!
var closeTime = game.closeTime.toString();
myReservationD[x] = closeTime;
x++;
});
self.io.sockets.in(socket.handshake.session._id).emit('myReserveList', { data : myReservationD });
}
});
});
socket.on('selectSlot', function (dat) {
var now = Date.now();
if((socket.handshake.session && socket.handshake.session.loggedIn === true) && (new Date(socket.handshake.session.cookie._expires).getTime() > now))
{
var resCheckFin = false;
var gameCheckFin = false;
var selectedSlotDate = new Date(dat.slotTime);
socket.handshake.session.touch().save();
var keys = getKeys(selectedSlots);
Reservation.find().select('closeTime').where('closeTime').equals(selectedSlotDate.getTime()).exec(function (err,reservationData) {
if(err)
{
console.log(err);
}
else
{
if(reservationData.length > 0)
{
self.io.sockets.in(socket.handshake.session._id).emit('slotUnavailable');
}
else
{
resCheckFin = true;
checkArray(resCheckFin,gameCheckFin);
}
}
});
Game.find().select('closeTime').where('closeTime').equals(selectedSlotDate.getTime()).exec(function (err,gameData) {
if(err)
{
console.log(err);
}
else
{
if(gameData.length > 0)
{
self.io.sockets.in(socket.handshake.session._id).emit('slotUnavailable');
}
else
{
gameCheckFin = true;
checkArray(resCheckFin,gameCheckFin);
}
}
});
var checkArray = function (resCheckFin,gameCheckFin)
{
if(gameCheckFin === true && resCheckFin === true)
{
var unavailable = 0;
for(var mkey in selectedSlots)
{
if(selectedSlots[mkey].selectedSlot !== null)
{
if(mkey !== socket.handshake.session._id)
{
if(selectedSlots[mkey].selectedSlot.getTime() === selectedSlotDate.getTime())
{
self.io.sockets.in(socket.handshake.session._id).emit('slotUnavailable');
unavailable ++;
}
}
}
}
if(unavailable === 0)
{
var keys = getKeys(this.selectedSlots);
if(keys.indexOf(socket.handshake.session._id)=== -1)
{
var newMall = ResMall.initMall(socket.handshake.session._id,selectedSlotDate);
selectedSlots[socket.handshake.session._id] = newMall;
}
else
{
selectedSlots[socket.handshake.session._id].slotTime = selectedSlotDate;
}
self.io.sockets.in(socket.handshake.session._id).emit('slotAvailable');
self.io.of('/mall/reservation').emit('slotSelected', { data : { slotTime : selectedSlotDate.toString() } });
}
}
};
}
else
{
//socket.emit('sessionTimeout',function (){
//});
}
});
socket.on('slotDiselected', function (data) {
var now = Date.now();
if((socket.handshake.session && socket.handshake.session.loggedIn === true) && (new Date(socket.handshake.session.cookie._expires).getTime() > now))
{
//socket.handshake.session.touch().save();
var keys = getKeys(selectedSlots);
if(keys.indexOf(socket.handshake.session._id) !== -1)
{
self.io.of('/mall/reservation').emit('slotDiselected', { data : { slotTime : selectedSlots[socket.handshake.session._id].selectedSlot.toString() } });
selectedSlots[socket.handshake.session._id].selectedSlot = null;
}
}
else
{
//socket.emit('sessionTimeout',function (){
// socket.handshake.session.destroy();
// socket.disconnect();
//});
}
});
socket.on('reserveSlot', function (data) {
var now = Date.now();
if((socket.handshake.session && socket.handshake.session.loggedIn === true) && (new Date(socket.handshake.session.cookie._expires).getTime() > now))
{
//socket.handshake.session.touch().save();
var resCheckFin = false;
var gameCheckFin = false;
var resSuccess = true;
var dedPntsSuccess = false;
var tranSuccess = false;
var resSave = false;
var selectedSlotDate = new Date(data.slotTime);
var keys = getKeys(selectedSlots);
console.log(selectedSlotDate);
console.log(keys.indexOf(socket.handshake.session._id));
if(keys.indexOf(socket.handshake.session._id)!== -1)
{
if(selectedSlots[socket.handshake.session._id].selectedSlot.getTime() === selectedSlotDate.getTime())
{
Reservation.find().select('closeTime').where('closeTime').equals(selectedSlotDate.getTime()).exec(function (err,reservationData) {
if(err)
{
console.log(err);
}
else
{
if(reservationData.length > 0)
{
self.io.sockets.in(socket.handshake.session._id).emit('reservationFail');
}
else
{
resCheckFin = true;
checkArray(resCheckFin,gameCheckFin);
}
}
});
Game.find().select('closeTime').where('closeTime').equals(selectedSlotDate.getTime()).exec(function (err,gameData) {
if(err)
{
console.log(err);
}
else
{
if(gameData.length > 0)
{
self.io.sockets.in(socket.handshake.session._id).emit('reservationFail');
}
else
{
gameCheckFin = true;
checkArray(resCheckFin,gameCheckFin);
}
}
});
}
else
{
self.io.sockets.in(socket.handshake.session._id).emit('reservationFail');
}
var calculateSlotPrice = function ()
{
Settings.find().select('slotPrice startDay lastDay lastHour slotDiscount').exec(function (err,settingsData) {
if(err)
{
console.log(err);
}
else
{
var slotPrice;
var slotPriceFound = false;
for(var i = 0;i < settingsData[0].slotPrice.length;i++)
{
if(slotPriceFound === true)
{
break;
}
if(settingsData[0].slotPrice[i].startDate.getTime() <= selectedSlotDate.getTime() && settingsData[0].slotPrice[i].finishDate.getTime() >= selectedSlotDate.getTime())
{
for(var y = 0;y < settingsData[0].slotPrice[i].slotPrice.length;y++)
{
console.log( settingsData[0].slotPrice[i].slotPrice);
if(settingsData[0].slotPrice[i].slotPrice[y].time == selectedSlotDate.getHours())
{
slotPrice = settingsData[0].slotPrice[i].slotPrice[y].price - settingsData[0].slotDiscount; //FIXED
slotPriceFound = true;
break;
}
}
}
}
deductPoints(slotPrice);
}
});
};
var deductPoints = function (slotPrice) {
Mall.findOne().select('pointsBalance').where('_id').equals(socket.handshake.session._id).exec(function (err,mallData) {
if(err)
{
console.log(err);
}
else
{
if(mallData.pointsBalance < slotPrice)
{
self.io.sockets.in(socket.handshake.session._id).emit('pointBalanceLow',{ msg : '우파루파머니가 부족합니다. 충전하시겠습니까?' });
self.io.of('/mall/reservation').emit('slotDiselected', { data : { slotTime : selectedSlotDate.selectedSlot.toString() } });
}
else
{
var newTransaction = new Transaction({ type : 1, amount : slotPrice, mallId : socket.handshake.session._id, details : '슬롯 구매 - ' + selectedSlotDate.toString() });
newTransaction.save(function (err) {
if(err)
{
self.io.sockets.in(socket.handshake.session._id).emit('reservationFail');
}
else
{
tranSuccess = true;
reservationFinished(dedPntsSuccess,tranSuccess,resSave);
}
});
var newRes = new Reservation({ closeTime : selectedSlotDate, mallId : socket.handshake.session._id, slotPrice : slotPrice });
newRes.save(function (err,newResDoc) {
if(err)
{
console.log(err);
}
else
{
resSave = true;
reservationFinished(dedPntsSuccess,tranSuccess,resSave);
}
});
mallData.pointsBalance = mallData.pointsBalance - slotPrice;
mallData.save(function (err) {
if(err)
{
console.log(err);
}
else
{
dedPntsSuccess = true;
reservationFinished(dedPntsSuccess,tranSuccess,resSave);
}
});
}
}
});
};
var reservationFinished = function (dedPntsSuccess,tranSuccess,resSave) {
if(dedPntsSuccess === true && tranSuccess === true && resSave === true)
{
self.io.sockets.in(socket.handshake.session._id).emit('reservationSuccess', { data : { slotTime : selectedSlotDate.toString() } });
self.io.of('/mall/reservation').emit('slotReserved', { data : { slotTime : selectedSlotDate.toString() } });
}
}
var checkArray = function (resCheckFin,gameCheckFin) {
if(resCheckFin === true && gameCheckFin === true)
{
for(var mKey in selectedSlots)
{
if(selectedSlots[mKey].selectedSlot !== null)
{
if(selectedSlots[mKey].selectedSlot.getTime() === selectedSlotDate.getTime() && mKey !== socket.handshake.session._id)
{
self.io.sockets.in(socket.handshake.session._id).emit('reservationFail')
resSuccess = false;
}
}
}
if(resSuccess === true)
{
calculateSlotPrice();
}
}
};
}
}
else
{
//socket.emit('sessionTimeout',function (){
//socket.handshake.session.destroy();
//socket.disconnect();
//});
}
});
socket.on('slotCancel',function (data) {
var now = Date.now();
var refundPoints = function (slotPrice) {
console.log(slotPrice);
Mall.update({ _id : socket.handshake.session._id },{ $inc : { pointsBalance : slotPrice } }, function (err,numAffected,raw) {
if(err)
{
console.log(err);
}
});
self.io.of('/mall/reservation').emit('slotCancelled',{ data : { slotTime : selectedSlotDate.toString() } });
};
if((socket.handshake.session && socket.handshake.session.loggedIn === true) && (new Date(socket.handshake.session.cookie._expires).getTime() > now))
{
//socket.handshake.session.touch().save();
var selectedSlotDate = new Date(data.slotTime);
Settings.find().select('cancelDay cancelHour').exec(function (err,settingData) {
if(err)
{
console.log(err);
}
else
{
var settingData = settingData[0];
var dateObj = new Date();
var cancelDate = new Date(selectedSlotDate.getTime() - ((settingData.cancelDay * Schedule.DAY_IN_MILLISECONDS))); // + ((settingData.cancelHour) * Schedule.HOUR_IN_MILLISECONDS)));
cancelDate = new Date(cancelDate.getTime() - ((cancelDate.getHours() * Schedule.HOUR_IN_MILLISECONDS) + (cancelDate.getMinutes() * Schedule.MINUTE_IN_MILLISECONDS)));
cancelDate = new Date(cancelDate.getTime() + (settingData.cancelHour * Schedule.HOUR_IN_MILLISECONDS));
if(selectedSlotDate.getHours() < settingData.lastHour && selectedSlot.getHours() < settingData.startHour)
{
cancelDate = cancelDate.getTime() - Schedule.DAY_IN_MILLISECONDS;
}
if(dateObj.getTime() < cancelDate.getTime())
{
Reservation.findOneAndRemove().where('mallId').equals(socket.handshake.session._id).where('closeTime').equals(selectedSlotDate.getTime()).exec(function (err,reservationData) {
if(err)
{
console.log(err);
}
else
{
if(selectedSlots[socket.handshake.session._id])
{
selectedSlots[socket.handshake.session._id].selectedSlot = null;
}
refundPoints(reservationData.slotPrice);
}
var tranDetail = '슬롯 예약 취소 - ' + reservationData.closeTime.toString();
var newTransaction = new Transaction({ type : 2, amount : reservationData.slotPrice, details : tranDetail, mallId : socket.handshake.session._id });
newTransaction.save(function (err) {
if(err)
{
console.log(err);
}
});
});
}
else
{
self.io.sockets.in(socket.handshake.session._id).emit('slotCancelledFail');
}
}
});
}
else
{
//socket.emit('sessionTimeout',function (){
//socket.handshake.session.destroy();
//socket.disconnect();
//});
}
});
socket.on('gameCancel',function (data) {
var now = Date.now();
var selectedSlotDate = new Date(data.slotTime);
var uploadToWorker = function (gameData) {
var connection = require('amqp').createConnection({ host : 'localhost'});
connection.on('ready', function () {
var exchange = connection.exchange('ooparoopa');
var queue = connection.queue('prizeImageDelete');
queue.on('queueDeclareOk', function (args) {
queue.bind(exchange,'#prizeImageDelete');
queue.on('queueBindOk', function () {
exchange.publish('#prizeImageDelete', gameData);
});
});
});
};
if((socket.handshake.session && socket.handshake.session.loggedIn === true) && (new Date(socket.handshake.session.cookie._expires).getTime() > now))
{
//socket.handshake.session.touch().save();
var selectedSlotData = new Date(data.slotTime);
Game.findOneAndRemove().where('mallId').equals(socket.handshake.session._id).where('closeTime').equals(selectedSlotDate.getTime()).exec(function (err,gameData) {
if(err)
{
console.log(err);
}
else
{
console.log(gameData);
var pointRefund = gameData.slotPrice + gameData.gamePrice;
Mall.update({ _id : socket.handshake.session._id }, { $inc : { pointsBalance : pointRefund } }, function (err,numAffected,raw) {
if(err)
{
console.log(err);
}
});
var newTransaction = new Transaction({ type : 2, amount : pointRefund, mallId : socket.handshake.session._id, details : '경기취소 - ' + selectedSlotDate.toString() });
newTransaction.save(function (err) {
if(err)
{
console.log(err);
}
});
uploadToWorker(gameData);
self.io.of('/mall/reservation').emit('gameCancelled', { data : { slotTime : selectedSlotDate.toString() } });
}
});
}
else
{
//socket.emit('sessionTimeout',function () {
// socket.handshake.session.destroy();
// socket.disconnect();
//});
}
});
}
else
{
//socket.emit('sessionTimeout',function (){
// socket.handshake.session.destroy();
// socket.disconnect();
//});
}
}
}
1355285492.579041 [0 127.0.0.1:42277] "publish" "close" "{\"nodeId\":1056825330,\"args\":[\"3tOPQ_40Lkh5vNTDRDLe\"]}"
1355285492.579074 [0 127.0.0.1:42280] "unsubscribe" "dispatch:3tOPQ_40Lkh5vNTDRDLe"
1355285492.579094 [0 127.0.0.1:42280] "subscribe" "dispatch:3tOPQ_40Lkh5vNTDRDLe"
1355285492.579883 [0 127.0.0.1:42279] "subscribe" "dispatch:3tOPQ_40Lkh5vNTDRDLe"
1355285500.270337 [0 127.0.0.1:42279] "unsubscribe" "disconnect-force:BhK2BCKMWgzowu4ERDLh"
1355285500.270377 [0 127.0.0.1:42279] "unsubscribe" "heartbeat-clear:BhK2BCKMWgzowu4ERDLh"
1355285500.270397 [0 127.0.0.1:42278] "publish" "close" "{\"nodeId\":1251962569,\"args\":[\"BhK2BCKMWgzowu4ERDLh\"]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.