Skip to content

Commit 99cec25

Browse files
committed
Cherry-picked PRs from upstream repo
See: - collectiveidea#163 - collectiveidea#169
1 parent d65b0f9 commit 99cec25

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ bin
66
coverage
77
pkg/*
88
gemfiles/**/*.gemfile.lock
9+
.idea

lib/delayed/backend/active_record.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ def self.ready_to_run(worker_name, max_run_time)
6161
)
6262
end
6363

64+
# See: https://github.com/collectiveidea/delayed_job_active_record/pull/163
65+
def self.recover_from(_error)
66+
::ActiveRecord::Base.connection.verify!
67+
end
68+
6469
def self.before_fork
6570
::ActiveRecord::Base.clear_all_connections!
6671
end
@@ -122,6 +127,7 @@ def self.reserve_with_scope_using_default_sql(ready_scope, worker, now)
122127
end
123128
end
124129

130+
# See: https://github.com/collectiveidea/delayed_job_active_record/pull/169
125131
def self.reserve_with_scope_using_optimized_postgres(ready_scope, worker, now)
126132
# Custom SQL required for PostgreSQL because postgres does not support UPDATE...LIMIT
127133
# This locks the single record 'FOR UPDATE' in the subquery
@@ -131,7 +137,7 @@ def self.reserve_with_scope_using_optimized_postgres(ready_scope, worker, now)
131137
# use 'FOR UPDATE' and we would have many locking conflicts
132138
quoted_name = connection.quote_table_name(table_name)
133139
subquery = ready_scope.limit(1).lock(true).select("id").to_sql
134-
sql = "UPDATE #{quoted_name} SET locked_at = ?, locked_by = ? WHERE id IN (#{subquery}) RETURNING *"
140+
sql = "UPDATE #{quoted_name} SET locked_at = ?, locked_by = ? WHERE id = (#{subquery}) RETURNING *"
135141
reserved = find_by_sql([sql, now, worker.name])
136142
reserved[0]
137143
end

0 commit comments

Comments
 (0)