* adding support for new heartbeat_interval field on LoginAck

This commit is contained in:
Seth Call 2012-10-23 06:37:25 -05:00
parent e3027e831b
commit 520225aedf
2 changed files with 28 additions and 27 deletions

View File

@ -39,6 +39,8 @@ module JamRuby
end
end
@log.debug("deleting #{stale_clients.length} stale connections")
stale_clients.each do |client_id|
delete_connection(client_id)
end
@ -62,7 +64,6 @@ module JamRuby
@mq_router.publish_to_friends(friend_ids, friend_update, user_id)
end
end
#end
end
@ -111,7 +112,6 @@ module JamRuby
unless music_session_id.nil?
conn.exec("DELETE FROM music_sessions id = $1 AND 0 = (SELECT count(music_session_id) FROM connections where music_session_id = $1)", [music_session_id]).clear
end
# end
end
def destroy_if_empty(conn, music_session_id)
@ -225,34 +225,35 @@ module JamRuby
end
end
end
end
# Creates a connection manager, and associates the connection created by active_record with ourselves
def self.active_record_transaction(&block)
connection_manager = ConnectionManager.new
ActiveRecord::Base.connection_pool.with_connection do |connection|
# create a transaction, and pass the current connection to ConnectionManager.
# this lets the entire operation work with the same transaction,
# across Rails ActiveRecord and the pg-gem based code in ConnectionManager.
connection_manager.pg_conn = connection.instance_variable_get("@connection")
block.call(connection_manager)
def lock_connections(conn)
conn.exec("LOCK connections IN EXCLUSIVE MODE").clear
end
end
def lock_connections(conn)
conn.exec("LOCK connections IN EXCLUSIVE MODE").clear
end
def gather_friends(conn, user_id)
friend_ids = []
conn.exec("SELECT f1.friend_id as friend_id FROM friendships f1 WHERE f1.user_id = $1 AND f1.friend_id IN (SELECT f2.user_id FROM friendships f2 WHERE f2.friend_id = $1)", [user_id]) do |friend_results|
friend_results.each do |friend_result|
friend_ids.push(friend_result['friend_id'])
end
end
return friend_ids
end
def gather_friends(conn, user_id)
friend_ids = []
conn.exec("SELECT f1.friend_id as friend_id FROM friendships f1 WHERE f1.user_id = $1 AND f1.friend_id IN (SELECT f2.user_id FROM friendships f2 WHERE f2.friend_id = $1)", [user_id]) do |friend_results|
friend_results.each do |friend_result|
friend_ids.push(friend_result['friend_id'])
# Creates a connection manager, and associates the connection created by active_record with ourselves
def self.active_record_transaction(&block)
connection_manager = ConnectionManager.new
ActiveRecord::Base.connection_pool.with_connection do |connection|
# create a transaction, and pass the current connection to ConnectionManager.
# this lets the entire operation work with the same transaction,
# across Rails ActiveRecord and the pg-gem based code in ConnectionManager.
connection_manager.pg_conn = connection.instance_variable_get("@connection")
connection.transaction do
block.call(connection_manager)
end
end
end
return friend_ids
end
# end
end

View File

@ -37,8 +37,8 @@
end
# create a login ack (login was successful)
def login_ack(public_ip, client_id, token)
login_ack = Jampb::LoginAck.new(:public_ip => public_ip, :client_id => client_id, :token => token)
def login_ack(public_ip, client_id, token, heartbeat_interval)
login_ack = Jampb::LoginAck.new(:public_ip => public_ip, :client_id => client_id, :token => token, :heartbeat_interval => heartbeat_interval)
return Jampb::ClientMessage.new(:type => ClientMessage::Type::LOGIN_ACK, :route_to => CLIENT_TARGET, :login_ack => login_ack)
end