diff --git a/ruby/lib/jam_ruby/base_manager.rb b/ruby/lib/jam_ruby/base_manager.rb index 09fc2e1eb..9e8e612c5 100644 --- a/ruby/lib/jam_ruby/base_manager.rb +++ b/ruby/lib/jam_ruby/base_manager.rb @@ -22,6 +22,7 @@ module JamRuby # 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. + @log.debug "DEBUG_TRAN -1" manager.pg_conn = connection.instance_variable_get("@connection") if @@in_websocket_gateway @@ -34,7 +35,9 @@ module JamRuby ActiveRecord::Base.connection.execute('ROLLBACK') end else + @log.debug "DEBUG_TRAN -2" connection.transaction do + @log.debug "DEBUG_TRAN -3" yield manager end end diff --git a/ruby/lib/jam_ruby/connection_manager.rb b/ruby/lib/jam_ruby/connection_manager.rb index 0d0583f39..4ed60a919 100644 --- a/ruby/lib/jam_ruby/connection_manager.rb +++ b/ruby/lib/jam_ruby/connection_manager.rb @@ -405,13 +405,17 @@ SQL def join_music_session(user, client_id, music_session, as_musician, tracks, audio_latency, video_sources=nil) connection = nil + @log.debug "DEBUG_TRAN 1" ConnectionManager.active_record_transaction do |connection_manager| + @log.debug "DEBUG_TRAN 2" db_conn = connection_manager.pg_conn + @log.debug "DEBUG_TRAN 3" connection = Connection.find_by_client_id_and_user_id!(client_id, user.id) + @log.debug "DEBUG_TRAN 4" connection.join_the_session(music_session, as_musician, tracks, user, audio_latency, video_sources) - + @log.debug "DEBUG_TRAN 5" JamRuby::MusicSessionUserHistory.join_music_session(user.id, music_session.id) # connection.music_session_id = music_session.id # connection.as_musician = as_musician @@ -419,18 +423,34 @@ SQL # connection.joined_session_at = Time.now # associate_tracks(connection, tracks) # connection.save + @log.debug "DEBUG_TRAN 6" if connection.errors.any? + @log.debug "DEBUG_TRAN 7" raise ActiveRecord::Rollback else + @log.debug "DEBUG_TRAN 8" update_session_controller(music_session.id) end end + @log.debug "DEBUG_TRAN 9" connection end + def testfunc() + value = nil + + ConnectionManager.active_record_transaction do |connection_manager| + db_conn = connection_manager.pg_conn + value = 1 + raise ActiveRecord::Rollback + end + + value + end + # if a blk is passed in, upon success, it will be called and you can issue notifications # within the connection table lock def leave_music_session(user, connection, music_session, &blk) diff --git a/ruby/spec/jam_ruby/connection_manager_spec.rb b/ruby/spec/jam_ruby/connection_manager_spec.rb index 33bb6d517..b723d3f5d 100644 --- a/ruby/spec/jam_ruby/connection_manager_spec.rb +++ b/ruby/spec/jam_ruby/connection_manager_spec.rb @@ -569,5 +569,10 @@ describe ConnectionManager, no_transaction: true do # connection.errors.size.should == 0 end + # should be deleted + it "testfunc" do + @connman.testfunc.should eql 1 + end + end