Skip to content

Commit

Permalink
Merge pull request #917 from mledom/master
Browse files Browse the repository at this point in the history
Adding the queue name to the log output
  • Loading branch information
albus522 committed Mar 31, 2017
2 parents 056e069 + b24cf57 commit 51cf01f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/delayed/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def failed(job)
end

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

Expand All @@ -293,6 +293,10 @@ def max_run_time(job)

protected

def say_queue(queue)
" (queue=#{queue})" if queue
end

def handle_failed_job(job, error)
job.error = error
job_say job, "FAILED (#{job.attempts} prior attempts) with #{error.class.name}: #{error.message}", 'error'
Expand Down
10 changes: 9 additions & 1 deletion spec/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,23 @@
describe 'job_say' do
before do
@worker = Delayed::Worker.new
@job = double('job', :id => 123, :name => 'ExampleJob')
@job = double('job', :id => 123, :name => 'ExampleJob', :queue => nil)
end

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

it 'logs with job name, queue and id' do
expect(@job).to receive(:queue).and_return('test')
expect(@worker).to receive(:say).
with('Job ExampleJob (id=123) (queue=test) 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'

Expand Down

0 comments on commit 51cf01f

Please sign in to comment.