Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added Delay::Worker.delay_jobs configuration to allow delayed job to …

…operate in a test mode. When delay_jobs=false, all jobs are executed realtime; delay_jobs=true gives normal behavior with database backend.
  • Loading branch information...
commit 6c11015334aae131737d08e4888ed2f84a161623 1 parent b8a0cc5
@edwinv edwinv authored
View
10 lib/delayed/backend/base.rb
@@ -23,9 +23,13 @@ def enqueue(*args)
unless options[:payload_object].respond_to?(:perform)
raise ArgumentError, 'Cannot enqueue items which do not respond to perform'
end
-
- self.create(options).tap do |job|
- job.hook(:enqueue)
+
+ if Delayed::Worker.delay_jobs
+ self.create(options).tap do |job|
+ job.hook(:enqueue)
+ end
+ else
+ options[:payload_object].perform
end
end
View
7 lib/delayed/backend/shared_spec.rb
@@ -11,6 +11,7 @@ def create_job(opts = {})
Delayed::Worker.max_priority = nil
Delayed::Worker.min_priority = nil
Delayed::Worker.default_priority = 99
+ Delayed::Worker.delay_jobs = true
SimpleJob.runs = 0
described_class.delete_all
end
@@ -57,6 +58,12 @@ def create_job(opts = {})
described_class.enqueue SimpleJob.new
described_class.count.should == 1
end
+
+ it "should not increase count after enqueuing items when delay_jobs is false" do
+ Delayed::Worker.delay_jobs = false
+ described_class.enqueue SimpleJob.new
+ described_class.count.should == 0
+ end
it "should be able to set priority [DEPRECATED]" do
silence_warnings do
View
7 lib/delayed/message_sending.rb
@@ -10,12 +10,7 @@ def initialize(payload_class, target, options)
end
def method_missing(method, *args)
- payload_object = @payload_class.new(@target, method.to_sym, args)
- if Delayed::Worker.delay_jobs
- Job.enqueue({:payload_object => payload_object}.merge(@options))
- else
- payload_object.perform
- end
+ Job.enqueue({:payload_object => @payload_class.new(@target, method.to_sym, args)}.merge(@options))
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.