Skip to content

Commit

Permalink
Allow Delayed::Worker configuration to be reset, allowing RSpec to pa…
Browse files Browse the repository at this point in the history
…ss independent of order
  • Loading branch information
laserlemon committed Mar 22, 2012
1 parent 4a5d155 commit e6aa885
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
27 changes: 20 additions & 7 deletions lib/delayed/worker.rb
Expand Up @@ -8,14 +8,27 @@

module Delayed
class Worker
DEFAULT_SLEEP_DELAY = 5
DEFAULT_MAX_ATTEMPTS = 25
DEFAULT_MAX_RUN_TIME = 4.hours
DEFAULT_DEFAULT_PRIORITY = 0
DEFAULT_DELAY_JOBS = true
DEFAULT_QUEUES = []
DEFAULT_READ_AHEAD = 5

cattr_accessor :min_priority, :max_priority, :max_attempts, :max_run_time, :default_priority, :sleep_delay, :logger, :delay_jobs, :queues, :read_ahead
self.sleep_delay = 5
self.max_attempts = 25
self.max_run_time = 4.hours
self.default_priority = 0
self.delay_jobs = true
self.queues = []
self.read_ahead = 5

def self.reset
self.sleep_delay = DEFAULT_SLEEP_DELAY
self.max_attempts = DEFAULT_MAX_ATTEMPTS
self.max_run_time = DEFAULT_MAX_RUN_TIME
self.default_priority = DEFAULT_DEFAULT_PRIORITY
self.delay_jobs = DEFAULT_DELAY_JOBS
self.queues = DEFAULT_QUEUES
self.read_ahead = DEFAULT_READ_AHEAD
end

reset

# Add or remove plugins in this list before the worker is instantiated
cattr_accessor :plugins
Expand Down
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -46,3 +46,9 @@ def whatever(n, _); tell*n; end

handle_asynchronously :whatever
end

RSpec.configure do |config|
config.after(:each) do
Delayed::Worker.reset
end
end

0 comments on commit e6aa885

Please sign in to comment.