Class: GitLab::Exporter::Database::Base
- Inherits:
-
Object
- Object
- GitLab::Exporter::Database::Base
show all
- Defined in:
- lib/gitlab_exporter/database/base.rb
Overview
An abstract class for interacting with DB
It takes a connection string (e.g. “dbname=test port=5432”)
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(args) ⇒ Base
19
20
21
|
# File 'lib/gitlab_exporter/database/base.rb', line 19
def initialize(args)
@connection_string = args[:connection_string]
end
|
Class Method Details
.connection_pool ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/gitlab_exporter/database/base.rb', line 11
def self.connection_pool
@connection_pool ||= Hash.new do |h, connection_string|
h[connection_string] = ConnectionPool.new(size: 3, timeout: 5) do
PG.connect(connection_string)
end
end
end
|
Instance Method Details
#connection_pool ⇒ Object
27
28
29
|
# File 'lib/gitlab_exporter/database/base.rb', line 27
def connection_pool
self.class.connection_pool[@connection_string]
end
|
#run ⇒ Object
23
24
25
|
# File 'lib/gitlab_exporter/database/base.rb', line 23
def run
fail NotImplemented
end
|
#with_connection_pool ⇒ Object
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/gitlab_exporter/database/base.rb', line 31
def with_connection_pool
connection_pool.with do |conn|
begin
yield conn
rescue PG::UnableToSend => e
conn.reset
raise e
end
end
end
|