Commit f4fe502e authored by Ahmad Sherif's avatar Ahmad Sherif

Try resetting DB connection in case of a PG::UnableToSend exception

parent f23fb506
Pipeline #56016 failed with stage
in 57 seconds
PATH
remote: .
specs:
gitlab-monitor (2.1.0)
gitlab-monitor (2.2.0)
connection_pool (~> 2.2.1)
pg (~> 0.18.4)
quantile (~> 0.2.0)
......
......@@ -27,6 +27,17 @@ module GitLab
def connection_pool
self.class.connection_pool[@connection_string]
end
def with_connection_pool(&block)
connection_pool.with do |conn|
begin
yield conn
rescue PG::UnableToSend => e
conn.reset
raise e
end
end
end
end
end
end
......
......@@ -178,7 +178,7 @@ module GitLab
end
def stale_builds
connection_pool.with do |conn|
with_connection_pool do |conn|
conn.exec(STALE_BUILDS_QUERY)[0]["count"].to_i
end
rescue PG::UndefinedTable, PG::UndefinedColumn
......@@ -221,7 +221,7 @@ module GitLab
end
def exec_query_with_custom_random_page_cost(query)
connection_pool.with do |conn|
with_connection_pool do |conn|
conn.transaction do |trans|
trans.exec(SET_RANDOM_PAGE_COST)
trans.exec(query)
......@@ -232,7 +232,7 @@ module GitLab
def mirror_column?
@mirror_column ||=
begin
connection_pool.with do |conn|
with_connection_pool do |conn|
conn.exec(MIRROR_COLUMN_QUERY)[0]["exists"] == "t"
end
rescue PG::UndefinedColumn
......
......@@ -30,7 +30,7 @@ module GitLab
private
def execute(query)
connection_pool.with do |conn|
with_connection_pool do |conn|
conn.exec(construct_query(query))[0]["count"]
end
rescue PG::UndefinedTable, PG::UndefinedColumn
......
......@@ -15,7 +15,7 @@ module GitLab
SQL
def run
connection_pool.with do |conn|
with_connection_pool do |conn|
conn.exec(QUERY).each.with_object({}) do |row, stats|
stats[row.delete("relname")] = row
end
......
module GitLab
module Monitor
VERSION = "2.1.0".freeze
VERSION = "2.2.0".freeze
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment