mirror of https://github.com/codevalet/canary
Add the remainder of the Sentry DAO calls needed
This commit is contained in:
parent
d67a9086c1
commit
6e1a1ef172
|
@ -6,6 +6,7 @@ require 'sinatra/base'
|
|||
require 'sentry-api'
|
||||
|
||||
require 'canary/dao/jenkins'
|
||||
require 'canary/dao/sentry'
|
||||
|
||||
module CodeValet
|
||||
module Canary
|
||||
|
@ -34,7 +35,7 @@ module CodeValet
|
|||
haml :index,
|
||||
:layout => :_base,
|
||||
:locals => {
|
||||
:projects => projects,
|
||||
:sentry => DAO::Sentry.new,
|
||||
:jenkins => DAO::Jenkins.new,
|
||||
}
|
||||
end
|
||||
|
@ -42,18 +43,14 @@ module CodeValet
|
|||
get '/issue/:id' do
|
||||
issue = nil
|
||||
events = []
|
||||
begin
|
||||
issue = SentryApi.issue(params['id'])
|
||||
events = SentryApi.issue_events(params['id'])
|
||||
rescue StandardError => exc
|
||||
Raven.capture_exception(exc)
|
||||
end
|
||||
issue_id = params['id']
|
||||
sentry = DAO::Sentry.new
|
||||
|
||||
haml :issue,
|
||||
:layout => :_base,
|
||||
:locals => {
|
||||
:issue => issue,
|
||||
:events => events,
|
||||
:issue => sentry.issue_by(issue_id),
|
||||
:events => sentry.events_for_issue(issue_id),
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -44,7 +44,6 @@ module CodeValet::Canary::DAO
|
|||
def issues_for(project_key)
|
||||
return cache.get_or_set("SentryApi#project_issues(#{project_key})",
|
||||
:expires_in => CACHE_SECONDS) do
|
||||
|
||||
SentryApi.project_issues(project_key)
|
||||
end
|
||||
rescue *CodeValet::Canary::DAO::NET_ERRORS => e
|
||||
|
@ -56,6 +55,41 @@ module CodeValet::Canary::DAO
|
|||
return []
|
||||
end
|
||||
|
||||
|
||||
# Return the issue by the given Sentry issue ID
|
||||
#
|
||||
# This response will be cached
|
||||
#
|
||||
# @return [Struct]
|
||||
# @return [nil] in case of error
|
||||
def issue_by(id)
|
||||
return cache.get_or_set("SentryApi#issue(#{id})",
|
||||
:expires_in => 5 * CACHE_SECONDS) do
|
||||
SentryApi.issue(id)
|
||||
end
|
||||
rescue *CodeValet::Canary::DAO::NET_ERRORS => e
|
||||
@error = e
|
||||
return nil
|
||||
rescue StandardError => e
|
||||
@error = e
|
||||
Raven.capture_exception(e)
|
||||
return nil
|
||||
end
|
||||
|
||||
def events_for_issue(id)
|
||||
return cache.get_or_set("SentryApi#issue_events(#{id})",
|
||||
:expires_in => CACHE_SECONDS) do
|
||||
SentryApi.issue_events(id)
|
||||
end
|
||||
rescue *CodeValet::Canary::DAO::NET_ERRORS => e
|
||||
@error = e
|
||||
return nil
|
||||
rescue StandardError => e
|
||||
@error = e
|
||||
Raven.capture_exception(e)
|
||||
return nil
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def cache
|
||||
|
|
|
@ -72,11 +72,77 @@ describe CodeValet::Canary::DAO::Sentry do
|
|||
expect(dao).to be_errored
|
||||
end
|
||||
|
||||
it 'should cache the response from SentryApi#projects' do
|
||||
it 'should cache the response from SentryApi#project_issues' do
|
||||
expect(SentryApi).to receive(:project_issues).and_return(response)
|
||||
3.times do
|
||||
expect(dao.issues_for('rspec')).to eql(response)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it { should respond_to :issue_by }
|
||||
describe '#issue_by' do
|
||||
let(:dao) { described_class.new }
|
||||
subject(:issue) { dao.issue_by('fake-id') }
|
||||
let(:response) { Hash.new }
|
||||
|
||||
it 'should return SentryApi#issue' do
|
||||
expect(SentryApi).to receive(:issue).and_return(response)
|
||||
expect(issue).to eql(response)
|
||||
end
|
||||
|
||||
it 'should gracefully handle network errors' do
|
||||
expect(SentryApi).to receive(:issue).and_raise(Errno::ECONNRESET)
|
||||
expect(issue).to be_nil
|
||||
expect(dao).to be_errored
|
||||
end
|
||||
|
||||
it 'should gracefully handle and record unknown errors' do
|
||||
expect(SentryApi).to receive(:issue).and_raise(JSON::ParserError)
|
||||
expect(Raven).to receive(:capture_exception)
|
||||
|
||||
expect(issue).to be_nil
|
||||
expect(dao).to be_errored
|
||||
end
|
||||
|
||||
it 'should cache the response from SentryApi#issue' do
|
||||
expect(SentryApi).to receive(:issue).and_return(response)
|
||||
3.times do
|
||||
expect(dao.issue_by('fake-id')).to eql(response)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it { should respond_to :events_for_issue }
|
||||
describe '#events_for_issue' do
|
||||
let(:dao) { described_class.new }
|
||||
subject(:issue) { dao.events_for_issue('fake-id') }
|
||||
let(:response) { Hash.new }
|
||||
|
||||
it 'should return SentryApi#issue' do
|
||||
expect(SentryApi).to receive(:issue_events).and_return(response)
|
||||
expect(issue).to eql(response)
|
||||
end
|
||||
|
||||
it 'should gracefully handle network errors' do
|
||||
expect(SentryApi).to receive(:issue_events).and_raise(Errno::ECONNRESET)
|
||||
expect(issue).to be_nil
|
||||
expect(dao).to be_errored
|
||||
end
|
||||
|
||||
it 'should gracefully handle and record unknown errors' do
|
||||
expect(SentryApi).to receive(:issue_events).and_raise(JSON::ParserError)
|
||||
expect(Raven).to receive(:capture_exception)
|
||||
|
||||
expect(issue).to be_nil
|
||||
expect(dao).to be_errored
|
||||
end
|
||||
|
||||
it 'should cache the response from SentryApi#issue' do
|
||||
expect(SentryApi).to receive(:issue_events).and_return(response)
|
||||
3.times do
|
||||
expect(dao.events_for_issue('fake-id')).to eql(response)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,15 +38,16 @@
|
|||
%h3
|
||||
Recent issues
|
||||
.container
|
||||
- if projects.size == 0
|
||||
- projects = sentry.projects
|
||||
- if sentry.errored?
|
||||
|
||||
Something went wrong when querying the error service!
|
||||
|
||||
- else
|
||||
- projects.auto_paginate do |project|
|
||||
- projects.each do |project|
|
||||
%h4= project.name
|
||||
%p
|
||||
- events = SentryApi.project_issues(project.slug)
|
||||
- events = sentry.issues_for(project.slug)
|
||||
- unless events.size > 0
|
||||
No recent events (yay).
|
||||
- else
|
||||
|
|
Loading…
Reference in New Issue