Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Tracking Airbrake deploys

  • Loading branch information...
commit 1ad214c6b572b85d37817979e8c914e02c55c1e6 1 parent 7e2afbe
@iain authored
View
20 app/models/airbrake/deploy.rb
@@ -0,0 +1,20 @@
+class Airbrake::Deploy < ActiveRecord::Base
+
+ belongs_to :airbrake_project, :class_name => "Airbrake::Project"
+
+ validates_presence_of :airbrake_project_id
+
+ def self.import(project, deploys)
+ deploys.each do |data|
+ deploy = where(:airbrake_id => data[:id]).first || new(:airbrake_id => data[:id])
+ deploy.rails_env = data[:rails_env]
+ deploy.revision = data[:revision]
+ deploy.local_username = data[:local_username]
+ deploy.deployed_at = data[:created_at]
+ deploy.ends_at = data[:ends_at]
+ deploy.airbrake_project = project
+ deploy.save!
+ end
+ end
+
+end
View
1  app/models/airbrake/for_project.rb
@@ -3,6 +3,7 @@ module Airbrake::ForProject
def self.included(project)
project.has_one :airbrake_project, :class_name => "Airbrake::Project"
project.has_many :airbrake_errors, :through => :airbrake_project, :class_name => "Airbrake::Error"
+ project.has_many :airbrake_deploys, :through => :airbrake_project, :class_name => "Airbrake::Deploy"
end
def airbrake_project_id
View
5 app/models/airbrake/project.rb
@@ -1,7 +1,9 @@
class Airbrake::Project < ActiveRecord::Base
+
belongs_to :project
- has_many :airbrake_errors, :foreign_key => "airbrake_project_id", :primary_key => :airbrake_id
+ has_many :airbrake_errors, :foreign_key => "airbrake_project_id", :class_name => "Airbrake::Error", :primary_key => :airbrake_id
+ has_many :airbrake_deploys, :foreign_key => "airbrake_project_id", :class_name => "Airbrake::Deploy"
def to_label
"#{name} (##{airbrake_id})"
@@ -12,6 +14,7 @@ def self.import(data)
project.name = data[:name]
project.api_key = data[:api_key]
project.save!
+ Airbrake::Deploy.import(project, Array(data[:deploys]))
end
end
View
16 db/migrate/20120117184312_create_airbrake_deploys.rb
@@ -0,0 +1,16 @@
+class CreateAirbrakeDeploys < ActiveRecord::Migration
+ def change
+ create_table :airbrake_deploys do |t|
+ t.integer :airbrake_project_id
+ t.integer :airbrake_id
+ t.string :rails_env
+ t.string :revision
+ t.string :local_username
+ t.datetime :deployed_at
+ t.datetime :ends_at
+
+ t.timestamps
+ end
+ add_index :airbrake_deploys, :airbrake_project_id
+ end
+end
View
16 db/schema.rb
@@ -11,7 +11,21 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120116165047) do
+ActiveRecord::Schema.define(:version => 20120117184312) do
+
+ create_table "airbrake_deploys", :force => true do |t|
+ t.integer "airbrake_project_id"
+ t.integer "airbrake_id"
+ t.string "rails_env"
+ t.string "revision"
+ t.string "local_username"
+ t.datetime "deployed_at"
+ t.datetime "ends_at"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ add_index "airbrake_deploys", ["airbrake_project_id"], :name => "index_airbrake_deploys_on_airbrake_project_id"
create_table "airbrake_errors", :force => true do |t|
t.integer "airbrake_project_id", :null => false
View
21 lib/charts/errors.rb
@@ -5,7 +5,7 @@ class Errors
def self.[](project)
query = project.airbrake_errors.group("date").select("COUNT(airbrake_errors.id) AS count, DATE(airbrake_errors.occurred_at) AS date")
series = { false => "Unresolved", true => "Resolved" }.map do |v, name|
- data = query.where(:resolved => v).map { |x| [ Time.parse(x[:date]).to_i * 1000, x[:count] ] }
+ data = query.where(:resolved => v).map { |x| [ js_timestamp(Time.parse(x[:date])), x[:count] ] }
{ :name => name, :data => data, :pointInterval => 24 * 3600 * 1000 }
end
{
@@ -30,8 +30,9 @@ def self.[](project)
:maxZoom => 24 * 3600000,
:tickWidth => 1,
:lineWitdh => 1,
- :max => 1.day.from_now.to_i * 1000,
- :minorTickInterval => 'auto'
+ :max => js_timestamp(1.day.from_now),
+ :minorTickInterval => 'auto',
+ :plotBands => plotbands(project)
},
:yAxis => {
:title => { :text => "Amount" },
@@ -43,6 +44,20 @@ def self.[](project)
}
end
+ def self.plotbands(project)
+ project.airbrake_deploys.map do |deploy|
+ {
+ :from => js_timestamp(deploy.deployed_at - 5.hours),
+ :to => js_timestamp(deploy.deployed_at + 5.hours),
+ :color => 'rgba(40, 210, 40, 0.5)'
+ }
+ end.tap { |x| Rails.logger.debug x.inspect }
+ end
+
+ def self.js_timestamp(time)
+ time.to_time.to_i * 1000
+ end
+
end
end
View
7 script/airbrake_errors.rb
@@ -67,8 +67,11 @@ def get_errors(page = 1)
:project_id => group.search("project-id").first.content,
:error_message => group.search("error-message").first.content,
:notices => Nokogiri::XML(res.body).search("//notices/notice").map { |notice|
- { :id => notice.search("id").first.content, :created_at => notice.search("created-at").first.content }
- }
+ {
+ :id => notice.search("id").first.content,
+ :created_at => notice.search("created-at").first.content
+ }
+ }
}
local_response = $local_connection.post do |request|
View
46 script/airbrake_projects.rb
@@ -41,19 +41,43 @@ def puts(message)
doc = Nokogiri::XML(response.body)
doc.search("//projects/project").each do |project|
- data = {
- :id => project.search("id").first.content,
- :name => project.search("name").first.content,
- :api_key => project.search("api-key").first.content
- }
-
- local_response = $local_connection.post do |request|
- request.url "/airbrake/projects"
- request.body = { :project => data }
+
+ id = project.search("id").first.content
+
+ deploys = $connection.get do |req|
+ req.url "/projects/#{id}/deploys.xml"
+ req.params[:auth_token] = KEY
end
- local_response.on_complete do
- puts "Saved project #{data[:name]}"
+ deploys.on_complete do
+
+ puts "Got deploys for project #{id}"
+
+ data = {
+ :id => id,
+ :name => project.search("name").first.content,
+ :api_key => project.search("api-key").first.content,
+ :deploys => Nokogiri::XML(deploys.body).search("//projects/deploy").map { |deploy|
+ {
+ :id => deploy.search("id").first.content,
+ :rails_env => deploy.search("rails-env").first.content,
+ :revision => deploy.search("scm-revision").first.content,
+ :local_username => deploy.search("local-username").first.content,
+ :created_at => deploy.search("created-at").first.content,
+ :ends_at => deploy.search("ends-at").first.content
+ }
+ }
+ }
+
+ local_response = $local_connection.post do |request|
+ request.url "/airbrake/projects"
+ request.body = { :project => data }
+ end
+
+ local_response.on_complete do
+ puts "Saved project #{data[:name]}"
+ end
+
end
end
View
13 spec/factories/airbrake_deploys.rb
@@ -0,0 +1,13 @@
+# Read about factories at http://github.com/thoughtbot/factory_girl
+
+FactoryGirl.define do
+ factory :deploy do
+ airbrake_project_id 1
+ airbrake_id 1
+ rails_env "MyString"
+ revision "MyString"
+ local_username "MyString"
+ deployed_at "2012-01-17 19:43:12"
+ ends_at "2012-01-17 19:43:12"
+ end
+end
View
9 spec/models/airbrake/deploy_spec.rb
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+describe Airbrake::Deploy do
+
+ it { should belong_to :airbrake_project }
+
+ it { should validate_presence_of :airbrake_project_id }
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.