Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rescue exceptions and run job.fail in perform #88

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 29 additions & 25 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,72 @@ PATH
remote: .
specs:
resque_spec (0.14.4)
resque (>= 1.19.0)
resque (>= 1.25.1)
rspec-core (>= 2.5.0)
rspec-expectations (>= 2.5.0)
rspec-mocks (>= 2.5.0)

GEM
remote: https://rubygems.org/
specs:
coderay (1.0.8)
atomic (1.1.14)
coderay (1.1.0)
columnize (0.3.6)
debugger (1.6.1)
debugger (1.6.2)
columnize (>= 0.3.1)
debugger-linecache (~> 1.2.0)
debugger-ruby_core_source (~> 1.2.3)
debugger-linecache (1.2.0)
debugger-ruby_core_source (1.2.3)
diff-lcs (1.2.4)
method_source (0.8.1)
debugger-ruby_core_source (1.2.4)
diff-lcs (1.2.5)
method_source (0.8.2)
mono_logger (1.1.0)
multi_json (1.8.0)
pry (0.9.11.4)
coderay (~> 1.0.5)
multi_json (1.8.2)
pry (0.9.12.4)
coderay (~> 1.0)
method_source (~> 0.8)
slop (~> 3.4)
pry-debugger (0.2.2)
debugger (~> 1.3)
pry (~> 0.9.10)
rack (1.5.2)
rack-protection (1.5.0)
rack-protection (1.5.1)
rack
rake (10.1.0)
redis (3.0.4)
redis-namespace (1.3.1)
redis (~> 3.0.0)
redis (3.0.6)
redis-namespace (1.3.2)
redis (~> 3.0.4)
resque (1.25.1)
mono_logger (~> 1.0)
multi_json (~> 1.0)
redis-namespace (~> 1.2)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
resque-scheduler (2.0.1)
redis (>= 2.0.1)
resque (>= 1.20.0)
rufus-scheduler
resque-scheduler (2.3.1)
redis (>= 3.0.0)
resque (~> 1.25)
rufus-scheduler (~> 2.0)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.3)
rspec-expectations (2.14.0)
rspec-core (2.14.7)
rspec-expectations (2.14.4)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.1)
rufus-scheduler (2.0.22)
tzinfo (>= 0.3.23)
sinatra (1.4.3)
rspec-mocks (2.14.4)
rufus-scheduler (2.0.24)
tzinfo (>= 0.3.22)
sinatra (1.4.4)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
slop (3.4.3)
slop (3.4.7)
thread_safe (0.1.3)
atomic
tilt (1.4.1)
timecop (0.6.3)
tzinfo (1.0.1)
tzinfo (1.1.0)
thread_safe (~> 0.1)
vegas (0.1.11)
rack (>= 1.0.0)

Expand Down
7 changes: 6 additions & 1 deletion lib/resque_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ def new_job(queue_name, payload)
end

def perform(queue_name, payload)
new_job(queue_name, payload).perform
job = new_job(queue_name, payload)
begin
job.perform
rescue Object => e
job.fail(e)
end
end

def perform_or_store(queue_name, payload)
Expand Down
2 changes: 1 addition & 1 deletion resque_spec.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |s|

s.files = Dir.glob("lib/**/*") + %w(LICENSE README.md Rakefile)

s.add_runtime_dependency('resque', ['>= 1.19.0'])
s.add_runtime_dependency('resque', ['>= 1.25.1'])
s.add_runtime_dependency('rspec-core', ['>= 2.5.0'])
s.add_runtime_dependency('rspec-expectations', ['>= 2.5.0'])
s.add_runtime_dependency('rspec-mocks', ['>= 2.5.0'])
Expand Down
7 changes: 7 additions & 0 deletions spec/resque_spec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@
ResqueSpec.enqueue(:queue_name, NameFromClassMethod, 1)
ResqueSpec.queue_by_name(:queue_name).should be_empty
end

it "fails jobs" do
Resque::Job.any_instance.stub(:fail) { FailingJob.failures += 1 }
expect do
ResqueSpec.enqueue(:queue_name, FailingJob, 1)
end.to change(FailingJob, :failures).by(1)
end
end
end

Expand Down
15 changes: 15 additions & 0 deletions spec/support/test_classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ def queue
self.invocations = 0
end

class FailingJob
class << self
attr_accessor :failures

def perform(*args)
raise "failure!"
end

def queue
:failing_job
end
end
self.failures = 0
end

class NoQueueClass
class << self
attr_accessor :invocations
Expand Down