Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make failed? method return a bool.
  • Loading branch information
mcfiredrill authored and laserlemon committed Feb 24, 2012
1 parent 360618a commit 4df5d96
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/delayed/backend/base.rb
Expand Up @@ -61,7 +61,7 @@ def work_off(num = 100)
end

def failed?
failed_at
!!failed_at
end
alias_method :failed, :failed?

Expand Down
10 changes: 5 additions & 5 deletions lib/delayed/backend/shared_spec.rb
Expand Up @@ -459,7 +459,7 @@ def create_job(opts = {})
job = described_class.create! :handler => "--- !ruby/object:JobThatDoesNotExist {}"
worker.work_off
job.reload
job.failed_at.should_not be_nil
job.should be_failed
end
end
end
Expand All @@ -480,7 +480,7 @@ def create_job(opts = {})
@job.reload
@job.last_error.should =~ /did not work/
@job.attempts.should == 1
@job.failed_at.should_not be_nil
@job.should be_failed
end

it "should re-schedule jobs after failing" do
Expand Down Expand Up @@ -580,14 +580,14 @@ def create_job(opts = {})
it_should_behave_like "any failure more than Worker.max_attempts times"

it "should be failed if it failed more than Worker.max_attempts times" do
@job.reload.failed_at.should == nil
@job.reload.should_not be_failed
Delayed::Worker.max_attempts.times { worker.reschedule(@job) }
@job.reload.failed_at.should_not == nil
@job.reload.should be_failed
end

it "should not be failed if it failed fewer than Worker.max_attempts times" do
(Delayed::Worker.max_attempts - 1).times { worker.reschedule(@job) }
@job.reload.failed_at.should == nil
@job.reload.should_not be_failed
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/delayed/backend/test.rb
Expand Up @@ -58,7 +58,7 @@ def self.find_available(worker_name, limit = 5, max_run_time = Worker.max_run_ti
jobs = all.select do |j|
j.run_at <= db_time_now &&
(j.locked_at.nil? || j.locked_at < db_time_now - max_run_time || j.locked_by == worker_name) &&
j.failed_at.nil?
!j.failed?
end

jobs = jobs.select{|j| Worker.queues.include?(j.queue)} if Worker.queues.any?
Expand Down

0 comments on commit 4df5d96

Please sign in to comment.