Skip to content

Commit

Permalink
Merge a834eb0 into 62fd8ab
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaphin committed Apr 26, 2014
2 parents 62fd8ab + a834eb0 commit 3eae53f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
23 changes: 12 additions & 11 deletions lib/delayed/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Worker
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, :plugins, :destroy_failed_jobs, :exit_on_complete
:default_priority, :default_log_level, :sleep_delay, :logger, :delay_jobs,
:queues, :read_ahead, :plugins, :destroy_failed_jobs, :exit_on_complete

# Named queue into which jobs are enqueued by default
cattr_accessor :default_queue_name
Expand All @@ -31,13 +31,14 @@ class Worker
attr_accessor :name_prefix

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
self.default_log_level = DEFAULT_LOG_LEVEL
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
Expand Down Expand Up @@ -238,12 +239,12 @@ def failed(job)
end
end

def job_say(job, text, level = DEFAULT_LOG_LEVEL)
def job_say(job, text, level = default_log_level)
text = "Job #{job.name} (id=#{job.id}) #{text}"
say text, level
end

def say(text, level = DEFAULT_LOG_LEVEL)
def say(text, level = default_log_level)
text = "[Worker(#{name})] #{text}"
puts text unless @quiet
if logger
Expand Down
12 changes: 10 additions & 2 deletions spec/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@

it "logs with job name and id" do
expect(@worker).to receive(:say).
with('Job ExampleJob (id=123) message', Delayed::Worker::DEFAULT_LOG_LEVEL)
with('Job ExampleJob (id=123) message', Delayed::Worker.default_log_level)
@worker.job_say(@job, 'message')
end

it "has a configurable default log level" do
Delayed::Worker.default_log_level = 'error'

expect(@worker).to receive(:say).
with('Job ExampleJob (id=123) message', 'error')
@worker.job_say(@job, 'message')
end
end
Expand Down Expand Up @@ -143,7 +151,7 @@
it "logs a message on the default log's level" do
expect(@worker.logger).to receive(:send).
with("info", "#{@expected_time}: #{@worker_name} #{@text}")
@worker.say(@text, Delayed::Worker::DEFAULT_LOG_LEVEL)
@worker.say(@text, Delayed::Worker.default_log_level)
end
end
end

0 comments on commit 3eae53f

Please sign in to comment.