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
-(instance_age <=> other.instance_age)
when :prefer_older then
(instance_age <=> other.instance_age)
else
-(last_checked_in <=> other.last_checked_in)
end
end
|
#idle? ⇒ 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_time ⇒ Object
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_age ⇒ Object
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_connection ⇒ Object
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
|