Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'delayed_job_daemon' into guns

  • Loading branch information...
commit 706aa8b82d7ac899f09dd861ddefe4812e6252a7 2 parents 1c73fd3 + 4b52cbc
guns authored
View
11 Gemfile
@@ -1,11 +1,2 @@
source 'http://rubygems.org'
-gem 'activesupport', '~>3'
-gem 'daemons'
-
-group :development do
- gem 'rspec'
- gem 'rake'
- gem 'rails', '~>3'
- gem 'sqlite3-ruby'
- gem 'ruby-debug'
-end
+gemspec
View
14 Gemfile.lock
@@ -1,3 +1,10 @@
+PATH
+ remote: .
+ specs:
+ delayed_job (2.1.0.pre2)
+ activesupport (~> 3.0)
+ daemons
+
GEM
remote: http://rubygems.org/
specs:
@@ -37,7 +44,7 @@ GEM
abstract (>= 1.0.0)
i18n (0.4.1)
linecache (0.43)
- mail (2.2.5)
+ mail (2.2.6)
activesupport (>= 2.3.6)
mime-types
treetop (>= 1.4.5)
@@ -78,9 +85,10 @@ PLATFORMS
ruby
DEPENDENCIES
- activesupport (~> 3)
+ activesupport (~> 3.0)
daemons
- rails (~> 3)
+ delayed_job!
+ rails (~> 3.0)
rake
rspec
ruby-debug
View
7 README.textile
@@ -38,6 +38,13 @@ script/plugin install git://github.com/collectiveidea/delayed_job.git
After delayed_job is installed, you will need to setup the backend.
+h2. Rails
+
+As of delayed_job 2.1 it only supports Rails 3.0+.
+
+The 2.0.x gems work great with older versions of Rails, so check those out if you need them.
+
+
h2. Backends
delayed_job supports multiple backends for storing the job queue. "See the wiki for other backends":http://wiki.github.com/collectiveidea/delayed_job/backends besides Active Record.
View
8 delayed_job.gemspec
@@ -16,11 +16,13 @@ This gem is collectiveidea's fork (http://github.com/collectiveidea/delayed_job)
s.rdoc_options = ["--main", "README.textile", "--inline-source", "--line-numbers"]
s.require_paths = ["lib"]
s.test_files = Dir.glob('spec/**/*')
-
+
s.add_runtime_dependency 'daemons'
- s.add_runtime_dependency 'activesupport', '~>3.0'
+ s.add_runtime_dependency 'activesupport', '~>3.0'
s.add_development_dependency 'rspec'
+ s.add_development_dependency 'rake'
+ s.add_development_dependency 'rails', '~>3.0'
s.add_development_dependency 'sqlite3-ruby'
- s.add_development_dependency 'activerecord'
+ s.add_development_dependency 'ruby-debug'
end
View
8 lib/delayed/backend/active_record.rb
@@ -2,7 +2,7 @@
class ActiveRecord::Base
yaml_as "tag:ruby.yaml.org,2002:ActiveRecord"
-
+
def self.yaml_new(klass, tag, val)
klass.find(val['attributes']['id'])
rescue ActiveRecord::RecordNotFound
@@ -22,7 +22,7 @@ module ActiveRecord
class Job < ::ActiveRecord::Base
include Delayed::Backend::Base
set_table_name :delayed_jobs
-
+
before_save :set_default_run_at
scope :ready_to_run, lambda {|worker_name, max_run_time|
@@ -31,7 +31,7 @@ class Job < ::ActiveRecord::Base
scope :by_priority, order('priority ASC, run_at ASC')
def self.after_fork
- ::ActiveRecord::Base.connection.reconnect!
+ ::ActiveRecord::Base.establish_connection
end
# When a worker is exiting, make sure we don't have any locked jobs.
@@ -44,7 +44,7 @@ def self.find_available(worker_name, limit = 5, max_run_time = Worker.max_run_ti
scope = self.ready_to_run(worker_name, max_run_time)
scope = scope.scoped(:conditions => ['priority >= ?', Worker.min_priority]) if Worker.min_priority
scope = scope.scoped(:conditions => ['priority <= ?', Worker.max_priority]) if Worker.max_priority
-
+
::ActiveRecord::Base.silence do
scope.by_priority.all(:limit => limit)
end
View
9 lib/delayed/backend/shared_spec.rb
@@ -164,7 +164,7 @@ def create_job(opts = {})
end
end
- context "when another worker is already performing an task, it" do
+ context "when another worker is already performing a task, it" do
before :each do
@job = described_class.create :payload_object => SimpleJob.new, :locked_by => 'worker1', :locked_at => described_class.db_time_now - 5.minutes
end
@@ -181,10 +181,9 @@ def create_job(opts = {})
@job.locked_at = described_class.db_time_now - 5.hours
@job.save
- @job.lock_exclusively! 4.hours, 'worker2'
- @job.reload
- @job.locked_by.should == 'worker2'
- @job.locked_at.should > (described_class.db_time_now - 1.minute)
+ @job.lock_exclusively!(4.hours, 'worker2').should be_true
+
+ described_class.find_available('worker2').should_not be_empty
end
it "should not be found by another worker" do
View
2  lib/delayed/performable_method.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/module/delegation'
+
module Delayed
class PerformableMethod < Struct.new(:object, :method_name, :args)
delegate :method, :to => :object
View
8 spec/active_record_job_spec.rb
@@ -5,7 +5,7 @@
after do
Time.zone = nil
end
-
+
it_should_behave_like 'a delayed_job backend'
context "db_time_now" do
@@ -13,7 +13,7 @@
Time.zone = 'Eastern Time (US & Canada)'
%w(EST EDT).should include(Delayed::Job.db_time_now.zone)
end
-
+
it "should return UTC time if that is the AR default" do
Time.zone = nil
ActiveRecord::Base.default_timezone = :utc
@@ -26,10 +26,10 @@
%w(CST CDT).should include(Delayed::Backend::ActiveRecord::Job.db_time_now.zone)
end
end
-
+
describe "after_fork" do
it "should call reconnect on the connection" do
- ActiveRecord::Base.connection.should_receive(:reconnect!)
+ ActiveRecord::Base.should_receive(:establish_connection)
Delayed::Backend::ActiveRecord::Job.after_fork
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.