Commit 91847531 authored by Felipe Artur's avatar Felipe Artur

Log project services errors when executing async

parent fab15563
...@@ -7,6 +7,10 @@ class ProjectServiceWorker ...@@ -7,6 +7,10 @@ class ProjectServiceWorker
def perform(hook_id, data) def perform(hook_id, data)
data = data.with_indifferent_access data = data.with_indifferent_access
Service.find(hook_id).execute(data) service = Service.find(hook_id)
service.execute(data)
rescue => error
service_class = service&.class&.name || "Not Found"
logger.error class: self.class.name, service_class: service_class, message: error.message
end end
end end
---
title: Log project services errors when executing async
merge_request:
author:
type: other
# frozen_string_literal: true
require 'spec_helper'
describe ProjectServiceWorker, '#perform' do
let(:worker) { described_class.new }
let(:service) { JiraService.new }
before do
allow(Service).to receive(:find).and_return(service)
end
it 'executes service with given data' do
data = { test: 'test' }
expect(service).to receive(:execute).with(data)
worker.perform(1, data)
end
it 'logs error messages' do
allow(service).to receive(:execute).and_raise(StandardError, 'invalid URL')
expect(Sidekiq.logger).to receive(:error).with({ class: described_class.name, service_class: service.class.name, message: "invalid URL" })
worker.perform(1, {})
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