Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Minor refactoring of Delayed::Job.enqueue to DRY up handling of Evale…

…dJobs
  • Loading branch information...
commit d644b3dd0ac19d43c8d2c97b8aef57d7b82a60ea 1 parent 89c3a0b
@vandrijevik vandrijevik authored
Showing with 8 additions and 14 deletions.
  1. +8 −14 lib/delayed/job.rb
View
22 lib/delayed/job.rb
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.