Skip to content

Commit

Permalink
Minor refactoring of Delayed::Job.enqueue to DRY up handling of Evale…
Browse files Browse the repository at this point in the history
…dJobs
  • Loading branch information
Vladimir Andrijevik committed Nov 30, 2008
1 parent 89c3a0b commit d644b3d
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions lib/delayed/job.rb
Expand Up @@ -77,22 +77,16 @@ def reschedule(message, backtrace = [], time = nil)
end

def self.enqueue(*args, &block)
if block_given?
priority = args.first || 0
run_at = args.second

Job.create(:payload_object => EvaledJob.new(&block), :priority => priority.to_i, :run_at => run_at)
else
object = args.first
priority = args.second || 0
run_at = args.third

unless object.respond_to?(:perform)
raise ArgumentError, 'Cannot enqueue items which do not respond to perform'
end
object = block_given? ? EvaledJob.new(&block) : args.shift

Job.create(:payload_object => object, :priority => priority.to_i, :run_at => run_at)
unless object.respond_to?(:perform) || block_given?
raise ArgumentError, 'Cannot enqueue items which do not respond to perform'
end

priority = args.first || 0
run_at = args.second

Job.create(:payload_object => object, :priority => priority.to_i, :run_at => run_at)
end

def self.find_available(limit = 5, max_run_time = MAX_RUN_TIME)
Expand Down

0 comments on commit d644b3d

Please sign in to comment.