Skip to content

Commit

Permalink
Remove refactor to define a DEFAULT_DESTROY_FAILED_JOBS
Browse files Browse the repository at this point in the history
  • Loading branch information
edgibbs committed Feb 24, 2015
1 parent 0d44f56 commit 555ad4a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/delayed/backend/shared_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,17 +460,17 @@ def create_job(opts = {})
end

it 'results in the default destroy failed jobs setting when not defined' do
expect(worker.destroy_failed_jobs(@job)).to eq(Delayed::Worker::DEFAULT_DESTROY_FAILED_JOBS)
expect(worker.destroy_failed_jobs(@job)).to be true
end

it 'uses the destroy failed jobs value on the payload when defined' do
expect(@job.payload_object).to receive(:destroy_failed_jobs).and_return(true)
expect(@job.destroy_failed_jobs).to be_truthy
expect(@job.destroy_failed_jobs).to be true
end

it 'results in an overridden destroy failed jobs value when defined' do
expect(@job.payload_object).to receive(:destroy_failed_jobs).and_return(true).twice
expect(worker.destroy_failed_jobs(@job)).to be_truthy
expect(worker.destroy_failed_jobs(@job)).to be true
end
end

Expand Down
6 changes: 4 additions & 2 deletions lib/delayed/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class Worker # rubocop:disable ClassLength
DEFAULT_DELAY_JOBS = true
DEFAULT_QUEUES = []
DEFAULT_READ_AHEAD = 5
DEFAULT_DESTROY_FAILED_JOBS = true

cattr_accessor :min_priority, :max_priority, :max_attempts, :max_run_time,
:default_priority, :sleep_delay, :logger, :delay_jobs, :queues,
Expand All @@ -40,7 +39,6 @@ def self.reset
self.delay_jobs = DEFAULT_DELAY_JOBS
self.queues = DEFAULT_QUEUES
self.read_ahead = DEFAULT_READ_AHEAD
self.destroy_failed_jobs = DEFAULT_DESTROY_FAILED_JOBS
@lifecycle = nil
end

Expand All @@ -49,6 +47,10 @@ def self.reset
# Add or remove plugins in this list before the worker is instantiated
self.plugins = [Delayed::Plugins::ClearLocks]

# By default failed jobs are destroyed after too many attempts. If you want to keep them around
# (perhaps to inspect the reason for the failure), set this to false.
self.destroy_failed_jobs = true

# By default, Signals INT and TERM set @exit, and the worker exits upon completion of the current job.
# If you would prefer to raise a SignalException and exit immediately you can use this.
# Be aware daemons uses TERM to stop and restart
Expand Down

0 comments on commit 555ad4a

Please sign in to comment.