Skip to content

Commit

Permalink
Fix RuboCop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Jun 25, 2014
1 parent ca7279e commit d3ce893
Show file tree
Hide file tree
Showing 27 changed files with 515 additions and 490 deletions.
4 changes: 2 additions & 2 deletions benchmarks.rb
Expand Up @@ -6,8 +6,8 @@

Benchmark.bm(10) do |x|
Delayed::Job.delete_all
n = 10000
n.times { "foo".delay.length }
n = 10_000
n.times { 'foo'.delay.length }

x.report { Delayed::Worker.new(:quiet => true).work_off(n) }
end
8 changes: 4 additions & 4 deletions delayed_job.gemspec
@@ -1,9 +1,9 @@
Gem::Specification.new do |spec|
spec.add_dependency 'activesupport', ['>= 3.0', '< 4.2']
spec.authors = ["Brandon Keepers", "Brian Ryckbost", "Chris Gaffney", "David Genord II", "Erik Michaels-Ober", "Matt Griffin", "Steve Richert", "Tobias Lütke"]
spec.description = "Delayed_job (or DJ) encapsulates the common pattern of asynchronously executing longer tasks in the background. It is a direct extraction from Shopify where the job table is responsible for a multitude of core tasks."
spec.add_dependency 'activesupport', ['>= 3.0', '< 4.2']
spec.authors = ['Brandon Keepers', 'Brian Ryckbost', 'Chris Gaffney', 'David Genord II', 'Erik Michaels-Ober', 'Matt Griffin', 'Steve Richert', 'Tobias Lütke']
spec.description = 'Delayed_job (or DJ) encapsulates the common pattern of asynchronously executing longer tasks in the background. It is a direct extraction from Shopify where the job table is responsible for a multitude of core tasks.'
spec.email = ['brian@collectiveidea.com']
spec.files = %w(CHANGELOG.md CONTRIBUTING.md LICENSE.md README.md Rakefile delayed_job.gemspec)
spec.files = %w[CHANGELOG.md CONTRIBUTING.md LICENSE.md README.md Rakefile delayed_job.gemspec]
spec.files += Dir.glob('{contrib,lib,recipes,spec}/**/*')
spec.homepage = 'http://github.com/collectiveidea/delayed_job'
spec.licenses = ['MIT']
Expand Down
40 changes: 19 additions & 21 deletions lib/delayed/backend/base.rb
Expand Up @@ -16,17 +16,17 @@ def enqueue(*args)
options[:payload_object] ||= args.shift

if args.size > 0
warn "[DEPRECATION] Passing multiple arguments to `#enqueue` is deprecated. Pass a hash with :priority and :run_at."
warn '[DEPRECATION] Passing multiple arguments to `#enqueue` is deprecated. Pass a hash with :priority and :run_at.'
options[:priority] = args.first || options[:priority]
options[:run_at] = args[1]
end

unless options[:payload_object].respond_to?(:perform)
raise ArgumentError, 'Cannot enqueue items which do not respond to perform'
fail(ArgumentError.new('Cannot enqueue items which do not respond to perform'))
end

if Delayed::Worker.delay_jobs
self.new(options).tap do |job|
new(options).tap do |job|
Delayed::Worker.lifecycle.run_callbacks(:enqueue, job) do
job.hook(:enqueue)
job.save
Expand All @@ -48,7 +48,7 @@ def reserve(worker, max_run_time = Worker.max_run_time)
end

# Allow the backend to attempt recovery from reserve errors
def recover_from(error)
def recover_from(_error)
end

# Hook method that is called before a new worker is forked
Expand All @@ -60,7 +60,7 @@ def after_fork
end

def work_off(num = 100)
warn "[DEPRECATION] `Delayed::Job.work_off` is deprecated. Use `Delayed::Worker.new.work_off instead."
warn '[DEPRECATION] `Delayed::Job.work_off` is deprecated. Use `Delayed::Worker.new.work_off instead.'
Delayed::Worker.new.work_off(num)
end
end
Expand All @@ -70,12 +70,10 @@ def failed?
end
alias_method :failed, :failed?

ParseObjectFromYaml = /\!ruby\/\w+\:([^\s]+)/
ParseObjectFromYaml = /\!ruby\/\w+\:([^\s]+)/ # rubocop:disable ConstantName

def name
@name ||= payload_object.respond_to?(:display_name) ?
payload_object.display_name :
payload_object.class.name
@name ||= payload_object.respond_to?(:display_name) ? payload_object.display_name : payload_object.class.name
rescue DeserializationError
ParseObjectFromYaml.match(handler)[1]
end
Expand All @@ -87,15 +85,14 @@ def payload_object=(object)

def payload_object
if YAML.respond_to?(:unsafe_load)
#See https://github.com/dtao/safe_yaml
#When the method is there, we need to load our YAML like this...
@payload_object ||= YAML.load(self.handler, :safe => false)
# See https://github.com/dtao/safe_yaml
# When the method is there, we need to load our YAML like this...
@payload_object ||= YAML.load(handler, :safe => false)
else
@payload_object ||= YAML.load(self.handler)
@payload_object ||= YAML.load(handler)
end
rescue TypeError, LoadError, NameError, ArgumentError => e
raise DeserializationError,
"Job failed to load: #{e.message}. Handler: #{handler.inspect}"
raise(DeserializationError.new("Job failed to load: #{e.message}. Handler: #{handler.inspect}"))
end

def invoke_job
Expand All @@ -104,7 +101,7 @@ def invoke_job
hook :before
payload_object.perform
hook :success
rescue Exception => e
rescue => e
hook :error, e
raise e
ensure
Expand All @@ -124,14 +121,15 @@ def hook(name, *args)
method = payload_object.method(name)
method.arity == 0 ? method.call : method.call(self, *args)
end
rescue DeserializationError
# do nothing
rescue DeserializationError # rubocop:disable HandleExceptions
end

def reschedule_at
payload_object.respond_to?(:reschedule_at) ?
payload_object.reschedule_at(self.class.db_time_now, attempts) :
self.class.db_time_now + (attempts ** 4) + 5
if payload_object.respond_to?(:reschedule_at)
payload_object.reschedule_at(self.class.db_time_now, attempts)
else
self.class.db_time_now + (attempts**4) + 5
end
end

def max_attempts
Expand Down

0 comments on commit d3ce893

Please sign in to comment.