Skip to content

Commit

Permalink
Fix PG bug
Browse files Browse the repository at this point in the history
  • Loading branch information
unionsmarket committed Jan 16, 2014
1 parent 711f08d commit e6e049b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/delayed/backend/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ def self.reserve(worker, max_run_time = Worker.max_run_time)
# 'FOR UPDATE' and we would have many locking conflicts
quoted_table_name = self.connection.quote_table_name(self.table_name)
subquery_sql = ready_scope.limit(1).lock(true).select('id').to_sql
reserved = self.find_by_sql(["UPDATE #{quoted_table_name} SET locked_at = ?, locked_by = ? WHERE id IN (#{subquery_sql}) RETURNING *", now, worker.name])
reserved = []
transaction do
reserved = self.find_by_sql(["UPDATE #{quoted_table_name} SET locked_at = ?, locked_by = ? WHERE id IN (#{subquery_sql}) RETURNING *", now, worker.name])
end
reserved[0]
when "MySQL", "Mysql2"
# This works on MySQL and possibly some other DBs that support UPDATE...LIMIT. It uses separate queries to lock and return the job
Expand Down

0 comments on commit e6e049b

Please sign in to comment.