Module: FiberedMysql2::FiberedMysql2Adapter_5_2
- Defined in:
- lib/active_record/connection_adapters/fibered_mysql2_adapter.rb
Instance Method Summary collapse
Instance Method Details
#expire ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/active_record/connection_adapters/fibered_mysql2_adapter.rb', line 35 def expire if in_use? # Because we are actively releasing connections from dead fibers, we only want # to enforce that we're expiring the current fibers connection, iff the owner # of the connection is still alive. if owner_fiber.alive? && owner_fiber != Fiber.current raise ::ActiveRecord::ActiveRecordError, "Cannot expire connection, " \ "it is owned by a different fiber: #{owner_fiber}. " \ "Current fiber: #{Fiber.current}." end @idle_since = ::Concurrent.monotonic_time @owner = nil else raise ::ActiveRecord::ActiveRecordError, "Cannot expire connection, it is not currently leased." end end |
#lease ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/active_record/connection_adapters/fibered_mysql2_adapter.rb', line 20 def lease if in_use? msg = "Cannot lease connection, ".dup if owner_fiber == Fiber.current msg << "it is already leased by the current fiber." else msg << "it is already in use by a different fiber: #{owner_fiber}. " \ "Current fiber: #{Fiber.current}." end raise ::ActiveRecord::ActiveRecordError, msg end @owner = Fiber.current end |
#steal! ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/active_record/connection_adapters/fibered_mysql2_adapter.rb', line 53 def steal! if in_use? if owner_fiber != Fiber.current pool.send :remove_connection_from_thread_cache, self, owner_fiber @owner = Fiber.current end else raise ::ActiveRecord::ActiveRecordError, "Cannot steal connection, it is not currently leased." end end |