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

Tweak logging in worker

parent 270ed1e3
......@@ -30,10 +30,7 @@ module StatusPage
.new(user: user, project: project, issue_id: issue_id)
.execute
log_error(result.message) if result.error?
rescue => e
log_error(e.message)
raise
log_info(result.message) if result.error?
end
def user
......@@ -44,9 +41,8 @@ module StatusPage
strong_memoize(:project) { Project.find_by_id(project_id) }
end
def log_error(message)
preamble = "Failed to publish incident for project_id=#{project_id}, issue_id=#{issue_id}"
logger.error("#{preamble}: #{message}")
def log_info(message)
logger.info(structured_payload(message: message))
end
end
end
......@@ -50,9 +50,10 @@ describe StatusPage::PublishIncidentWorker do
let(:error_message) { 'some 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)
.to receive(:error).with(/#{error_message}/)
.to receive(:info)
.with(a_hash_including('message' => error_message))
.exactly(worker_exec_times).times
subject
......@@ -64,10 +65,9 @@ describe StatusPage::PublishIncidentWorker do
let(:error_message) { 'some exception' }
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)
expect(logger).to receive(:error).with(/#{error_message}/)
expect { subject }.to raise_error(exception)
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