Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #39 from agrobbin/master

Rails 4 compatibility
  • Loading branch information...
commit 2d9679912013e4d1bca42547029b61d404fc0a0c 2 parents a297748 + 0cb4496
@sferik sferik authored
View
2  delayed_job_active_record.gemspec
@@ -1,7 +1,7 @@
# coding: utf-8
Gem::Specification.new do |spec|
- spec.add_dependency 'activerecord', ['>= 2.1.0', '< 4']
+ spec.add_dependency 'activerecord', ['>= 3.0', '< 4.1']
spec.add_dependency 'delayed_job', '~> 3.0'
spec.authors = ["Brian Ryckbost", "Matt Griffin", "Erik Michaels-Ober"]
spec.description = 'ActiveRecord backend for Delayed::Job, originally authored by Tobias Lütke'
View
20 lib/delayed/backend/active_record.rb
@@ -7,8 +7,7 @@ module ActiveRecord
class Job < ::ActiveRecord::Base
include Delayed::Backend::Base
- attr_accessible :priority, :run_at, :queue, :payload_object,
- :failed_at, :locked_at, :locked_by
+ scope :by_priority, lambda { order('priority ASC, run_at ASC') }
before_save :set_default_run_at
@@ -23,10 +22,6 @@ def self.ready_to_run(worker_name, max_run_time)
where('(run_at <= ? AND (locked_at IS NULL OR locked_at < ?) OR locked_by = ?) AND failed_at IS NULL', db_time_now, db_time_now - max_run_time, worker_name)
end
- def self.by_priority
- order('priority ASC, run_at ASC')
- end
-
def self.before_fork
::ActiveRecord::Base.clear_all_connections!
end
@@ -37,7 +32,7 @@ def self.after_fork
# When a worker is exiting, make sure we don't have any locked jobs.
def self.clear_locks!(worker_name)
- update_all("locked_by = null, locked_at = null", ["locked_by = ?", worker_name])
+ where(:locked_by => worker_name).update_all(:locked_by => nil, :locked_at => nil)
end
def self.reserve(worker, max_run_time = Worker.max_run_time)
@@ -45,14 +40,13 @@ def self.reserve(worker, max_run_time = Worker.max_run_time)
readyScope = self.ready_to_run(worker.name, max_run_time)
# scope to filter to the single next eligible job
- nextScope = readyScope.scoped
- nextScope = nextScope.scoped(:conditions => ['priority >= ?', Worker.min_priority]) if Worker.min_priority
- nextScope = nextScope.scoped(:conditions => ['priority <= ?', Worker.max_priority]) if Worker.max_priority
- nextScope = nextScope.scoped(:conditions => ["queue IN (?)", Worker.queues]) if Worker.queues.any?
- nextScope = nextScope.scoped.by_priority.limit(1)
+ readyScope = readyScope.where('priority >= ?', Worker.min_priority) if Worker.min_priority
+ readyScope = readyScope.where('priority <= ?', Worker.max_priority) if Worker.max_priority
+ readyScope = readyScope.where(:queue => Worker.queues) if Worker.queues.any?
+ job = readyScope.by_priority.first
now = self.db_time_now
- job = nextScope.first
+
return unless job
job.with_lock do
job.locked_at = now
View
15 spec/delayed/backend/active_record_spec.rb
@@ -43,21 +43,6 @@
end
end
- context "ActiveRecord::Base.send(:attr_accessible, nil)" do
- before do
- Delayed::Backend::ActiveRecord::Job.send(:attr_accessible, nil)
- end
-
- after do
- Delayed::Backend::ActiveRecord::Job.send(:attr_accessible, *Delayed::Backend::ActiveRecord::Job.new.attributes.keys)
- end
-
- it "is still accessible" do
- job = Delayed::Backend::ActiveRecord::Job.enqueue :payload_object => EnqueueJobMod.new
- expect(Delayed::Backend::ActiveRecord::Job.find(job.id).handler).to_not be_blank
- end
- end
-
context "ActiveRecord::Base.table_name_prefix" do
it "when prefix is not set, use 'delayed_jobs' as table name" do
::ActiveRecord::Base.table_name_prefix = nil
View
2  spec/spec_helper.rb
@@ -44,7 +44,7 @@ class Story < ActiveRecord::Base
self.primary_key = :story_id
def tell; text; end
def whatever(n, _); tell*n; end
- default_scope where(:scoped => true)
+ default_scope { where(:scoped => true) }
handle_asynchronously :whatever
end
Please sign in to comment.
Something went wrong with that request. Please try again.