Commit 4ce65778 authored by Peter Leitzen's avatar Peter Leitzen

Tweak logging in worker

parent 270ed1e3
...@@ -30,10 +30,7 @@ module StatusPage ...@@ -30,10 +30,7 @@ module StatusPage
.new(user: user, project: project, issue_id: issue_id) .new(user: user, project: project, issue_id: issue_id)
.execute .execute
log_error(result.message) if result.error? log_info(result.message) if result.error?
rescue => e
log_error(e.message)
raise
end end
def user def user
...@@ -44,9 +41,8 @@ module StatusPage ...@@ -44,9 +41,8 @@ module StatusPage
strong_memoize(:project) { Project.find_by_id(project_id) } strong_memoize(:project) { Project.find_by_id(project_id) }
end end
def log_error(message) def log_info(message)
preamble = "Failed to publish incident for project_id=#{project_id}, issue_id=#{issue_id}" logger.info(structured_payload(message: message))
logger.error("#{preamble}: #{message}")
end end
end end
end end
...@@ -50,9 +50,10 @@ describe StatusPage::PublishIncidentWorker do ...@@ -50,9 +50,10 @@ describe StatusPage::PublishIncidentWorker do
let(:error_message) { 'some message' } let(:error_message) { 'some message' }
let(:service_result) { ServiceResponse.error(message: error_message) } let(:service_result) { ServiceResponse.error(message: error_message) }
it 'succeeds and logs the errors' do it 'succeeds and logs the error' do
expect(logger) expect(logger)
.to receive(:error).with(/#{error_message}/) .to receive(:info)
.with(a_hash_including('message' => error_message))
.exactly(worker_exec_times).times .exactly(worker_exec_times).times
subject subject
...@@ -64,10 +65,9 @@ describe StatusPage::PublishIncidentWorker do ...@@ -64,10 +65,9 @@ describe StatusPage::PublishIncidentWorker do
let(:error_message) { 'some exception' } let(:error_message) { 'some exception' }
let(:exception) { StandardError.new(error_message) } let(:exception) { StandardError.new(error_message) }
it 'logs and re-raises exception' do it 're-raises exception' do
allow(service).to receive(:execute).and_raise(exception) allow(service).to receive(:execute).and_raise(exception)
expect(logger).to receive(:error).with(/#{error_message}/)
expect { subject }.to raise_error(exception) expect { subject }.to raise_error(exception)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment