Skip to content

Commit 2807142

Browse files
committed
Replace use of ActiveRecord::Base.connection with with_connection
So that when running with `permanent_connection_checkout` set to `false`, this doesn't cause any problems. Using `connection` is deprecated in any case, so this was needed regardless.
1 parent 1957f57 commit 2807142

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

app/models/solid_queue/failed_execution.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ def exception_backtrace
5858
end
5959

6060
def determine_backtrace_size_limit
61-
column = self.class.connection.schema_cache.columns_hash(self.class.table_name)["error"]
62-
if column.limit.present?
61+
column = self.class.connection_pool.with_connection do |connection|
62+
connection.schema_cache.columns_hash(self.class.table_name)["error"]
63+
end
64+
65+
if column && column.limit.present?
6366
column.limit - exception_class_name.bytesize - exception_message.bytesize - JSON_OVERHEAD
6467
end
6568
end

app/models/solid_queue/record.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@ class Record < ActiveRecord::Base
66

77
connects_to(**SolidQueue.connects_to) if SolidQueue.connects_to
88

9-
def self.non_blocking_lock
10-
if SolidQueue.use_skip_locked
11-
lock(Arel.sql("FOR UPDATE SKIP LOCKED"))
12-
else
13-
lock
9+
class << self
10+
def non_blocking_lock
11+
if SolidQueue.use_skip_locked
12+
lock(Arel.sql("FOR UPDATE SKIP LOCKED"))
13+
else
14+
lock
15+
end
16+
end
17+
18+
def supports_insert_conflict_target?
19+
connection_pool.with_connection do |connection|
20+
connection.supports_insert_conflict_target?
21+
end
1422
end
1523
end
1624
end

app/models/solid_queue/recurring_execution.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class AlreadyRecorded < StandardError; end
88

99
class << self
1010
def create_or_insert!(**attributes)
11-
if connection.supports_insert_conflict_target?
11+
if supports_insert_conflict_target?
1212
# PostgreSQL fails and aborts the current transaction when it hits a duplicate key conflict
1313
# during two concurrent INSERTs for the same value of an unique index. We need to explicitly
1414
# indicate unique_by to ignore duplicate rows by this value when inserting

app/models/solid_queue/recurring_task.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def from_configuration(key, **options)
3636
end
3737

3838
def create_or_update_all(tasks)
39-
if connection.supports_insert_conflict_target?
39+
if supports_insert_conflict_target?
4040
# PostgreSQL fails and aborts the current transaction when it hits a duplicate key conflict
4141
# during two concurrent INSERTs for the same value of an unique index. We need to explicitly
4242
# indicate unique_by to ignore duplicate rows by this value when inserting

app/models/solid_queue/semaphore.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def signal_all(jobs)
2020

2121
# Requires a unique index on key
2222
def create_unique_by(attributes)
23-
if connection.supports_insert_conflict_target?
23+
if supports_insert_conflict_target?
2424
insert({ **attributes }, unique_by: :key).any?
2525
else
2626
create!(**attributes)

0 commit comments

Comments
 (0)