Skip to content

Commit

Permalink
Merge remote branch 'collectiveidea/master' into delayed_job_daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
guns committed Sep 15, 2010
2 parents e196028 + 234fcf8 commit 4b52cbc
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 29 deletions.
11 changes: 1 addition & 10 deletions 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
14 changes: 11 additions & 3 deletions 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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -78,9 +85,10 @@ PLATFORMS
ruby

DEPENDENCIES
activesupport (~> 3)
activesupport (~> 3.0)
daemons
rails (~> 3)
delayed_job!
rails (~> 3.0)
rake
rspec
ruby-debug
Expand Down
7 changes: 7 additions & 0 deletions README.textile
Expand Up @@ -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.
Expand Down
8 changes: 5 additions & 3 deletions delayed_job.gemspec
Expand Up @@ -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

8 changes: 4 additions & 4 deletions lib/delayed/backend/active_record.rb
Expand Up @@ -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
Expand All @@ -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|
Expand All @@ -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.
Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions lib/delayed/backend/shared_spec.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions 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
Expand Down
8 changes: 4 additions & 4 deletions spec/active_record_job_spec.rb
Expand Up @@ -5,15 +5,15 @@
after do
Time.zone = nil
end

it_should_behave_like 'a delayed_job backend'

context "db_time_now" do
it "should return time in current time zone if set" do
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
Expand All @@ -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
Expand Down

0 comments on commit 4b52cbc

Please sign in to comment.