Skip to content

Commit

Permalink
Merge 21d8f25 into 711f08d
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelglass committed Oct 23, 2013
2 parents 711f08d + 21d8f25 commit dd0310f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/delayed/backend/active_record.rb
Expand Up @@ -63,11 +63,11 @@ def self.reserve(worker, max_run_time = Worker.max_run_time)
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[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
count = ready_scope.limit(1).update_all(:locked_at => now, :locked_by => worker.name)
return nil if count == 0
self.where(:locked_at => now, :locked_by => worker.name, :failed_at => nil).first
# 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
# count = ready_scope.limit(1).update_all(:locked_at => now, :locked_by => worker.name)
# return nil if count == 0
# self.where(:locked_at => now, :locked_by => worker.name, :failed_at => nil).first
when "MSSQL", "Teradata"
# The MSSQL driver doesn't generate a limit clause when update_all is called directly
subsubquery_sql = ready_scope.limit(1).to_sql
Expand Down

0 comments on commit dd0310f

Please sign in to comment.