Module: AdvancedConnection::ActiveRecordExt::AbstractAdapter

Extended by:
ActiveSupport::Autoload, ActiveSupport::Concern
Defined in:
lib/advanced_connection/active_record_ext/abstract_adapter.rb,
lib/advanced_connection/active_record_ext/abstract_adapter/statement_pooling.rb

Defined Under Namespace

Modules: StatementPooling

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/advanced_connection/active_record_ext/abstract_adapter.rb', line 65

def <=>(other)
  case pool.queue_type
    when :prefer_younger then
      # when prefering younger, we sort oldest->youngest
      # to ensure that older connections will be reaped
      # during #remove_idle_connections()
      -(instance_age <=> other.instance_age)
    when :prefer_older then
      # when prefering older, we sort youngest->oldest to
      # ensure that younger connections will be reaped
      # during #remove_idle_connections()
      (instance_age <=> other.instance_age)
    else
      # With fifo / lifo queues, we only care about the
      # last time a given connection was used (inferred
      # by when it was last checked into the pool).
      # This ensures that the longer idling connections
      # will be reaped.
      -(last_checked_in <=> other.last_checked_in)
  end
end

#idle?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/advanced_connection/active_record_ext/abstract_adapter.rb', line 61

def idle?
  idle_time > pool.max_idle_time
end

#idle_timeObject



57
58
59
# File 'lib/advanced_connection/active_record_ext/abstract_adapter.rb', line 57

def idle_time
  (in_use? ? 0.0 : Time.now - @last_checked_in).to_f
end

#initialize_with_advanced_connection(*args, &block) ⇒ Object



39
40
41
42
43
44
# File 'lib/advanced_connection/active_record_ext/abstract_adapter.rb', line 39

def initialize_with_advanced_connection(*args, &block)
  @instantiated_at  = Time.now
  @last_checked_in  = @instantiated_at
  @last_checked_out = false
  initialize_without_advanced_connection(*args, &block)
end

#instance_ageObject



53
54
55
# File 'lib/advanced_connection/active_record_ext/abstract_adapter.rb', line 53

def instance_age
  (Time.now - @instantiated_at).to_f
end

#lease_with_advanced_connectionObject



46
47
48
49
50
51
# File 'lib/advanced_connection/active_record_ext/abstract_adapter.rb', line 46

def lease_with_advanced_connection
  synchronize {
    @last_checked_out = Time.now
    lease_without_advanced_connection
  }
end