Commit bb8db654 authored by Maxwell Salzberg's avatar Maxwell Salzberg

add basic pod error logging, and added guard and removed autotest

parent 7956eb7d
......@@ -85,7 +85,9 @@ group :development do
end
group :test, :development do
gem 'factory_girl_rails', :require => false
gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i
gem 'guard-rspec'
gem 'factory_girl_rails', :require => false
unless ENV["TRAVIS"]
gem 'ruby-debug-base19', '0.11.23' if RUBY_VERSION.include? '1.9.1'
gem 'ruby-debug19', :platforms => :ruby_19
......
......@@ -209,6 +209,10 @@ GEM
gem_plugin (0.2.3)
gherkin (2.4.5)
json (>= 1.4.6)
guard (0.5.1)
thor (~> 0.14.6)
guard-rspec (0.4.0)
guard (>= 0.4.0)
haml (3.1.2)
hashie (1.0.0)
highline (1.6.2)
......@@ -347,6 +351,7 @@ GEM
rake (0.9.2)
rash (0.3.0)
hashie (~> 1.0.0)
rb-fsevent (0.4.1)
rcov (0.9.9)
rdoc (3.8)
redis (2.2.1)
......@@ -478,6 +483,7 @@ DEPENDENCIES
fog (= 0.3.25)
foreigner (= 0.9.1)
fuubar
guard-rspec
haml (= 3.1.2)
http_accept_language!
i18n-inflector-rails (~> 1.0)
......@@ -497,6 +503,7 @@ DEPENDENCIES
omniauth (= 0.2.6)
rails (= 3.0.9)
rails-i18n
rb-fsevent
rcov
resque (= 1.10.0)
resque-ensure-connected
......
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
# also, http://asciicasts.com/episodes/264-guard
guard 'rspec', :version => 2, :all_on_start => false do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('spec/spec_helper.rb') { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara request specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
end
......@@ -48,7 +48,10 @@ module Job
end
end
unless response.success?
Rails.logger.info("event=http_multi_fail sender_id=#{user_id} recipient_id=#{person.id} url=#{response.effective_url} response_code='#{response.code}' xml='#{Base64.decode64(enc_object_xml)}'")
pod = Pod.find_or_create_by_url(response.effective_url)
log_line = "event=http_multi_fail sender_id=#{user_id} recipient_id=#{person.id} url=#{response.effective_url} response_code='#{response.code}' xml='#{Base64.decode64(enc_object_xml)}'"
Rails.logger.info(log_line)
pod.pod_stats.create(:error_message => log_line, :person_id => person.id, :error_code => response.code.to_i)
failed_request_people << person.id
end
end
......
class Pod < ActiveRecord::Base
has_many :pod_stats
def self.find_or_create_by_url(url)
u = URI.parse(url)
pod = self.find_or_initialize_by_host(u.host)
unless pod.persisted?
pod.ssl = (u.scheme == 'https')? true : false
pod.save
end
pod
end
end
class PodStat < ActiveRecord::Base
belongs_to :pod
end
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'autotest/growl'
Autotest.add_discovery { "rails" }
Autotest.add_discovery { "rspec2" }
Autotest.add_hook :initialize do |at|
at.add_mapping(%r%^spec/(intergration|mailers|config)/.*rb$%) { |filename, _|
filename
}
at.add_mapping(%r%^spec/misc_spec.rb$%) { |filename, _|
filename
}
end
class CreatePods < ActiveRecord::Migration
def self.up
create_table :pods do |t|
t.string :host
t.boolean :ssl
t.timestamps
end
end
def self.down
drop_table :pods
end
end
class CreatePodStats < ActiveRecord::Migration
def self.up
create_table :pod_stats do |t|
t.integer :error_code
t.integer :person_id
t.text :error_message
t.integer :pod_id
t.timestamps
end
end
def self.down
drop_table :pod_stats
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110729045734) do
ActiveRecord::Schema.define(:version => 20110730173443) do
create_table "aspect_memberships", :force => true do |t|
t.integer "aspect_id", :null => false
......@@ -233,6 +233,22 @@ ActiveRecord::Schema.define(:version => 20110729045734) do
add_index "people", ["guid"], :name => "index_people_on_guid", :unique => true
add_index "people", ["owner_id"], :name => "index_people_on_owner_id", :unique => true
create_table "pod_stats", :force => true do |t|
t.integer "error_code"
t.integer "person_id"
t.text "error_message"
t.integer "pod_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "pods", :force => true do |t|
t.string "host"
t.boolean "ssl"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "post_visibilities", :force => true do |t|
t.integer "post_id", :null => false
t.datetime "created_at"
......
......@@ -63,3 +63,4 @@ time_interval = 1000
time_interval += 1000
end
end
puts "successfully seed the db with users eve, bob, and alice (password: 'evankorth')"
......@@ -14,8 +14,8 @@ describe Job::HttpMulti do
@hydra = Typhoeus::Hydra.new
@response = Typhoeus::Response.new(:code => 200, :headers => "", :body => "", :time => 0.2)
@failed_response = Typhoeus::Response.new(:code => 504, :headers => "", :body => "", :time => 0.2)
@response = Typhoeus::Response.new(:code => 200, :headers => "", :body => "", :time => 0.2, :effective_url => 'http://foobar.com')
@failed_response = Typhoeus::Response.new(:code => 504, :headers => "", :body => "", :time => 0.2, :effective_url => 'http://foobar.com')
end
it 'POSTs to more than one person' do
......@@ -71,7 +71,7 @@ describe Job::HttpMulti do
person = @people.first
person.url = 'http://remote.net/'
person.save
response = Typhoeus::Response.new(:code => 301, :headers_hash => {"Location" => person.receive_url.sub('http://', 'https://')}, :body => "", :time => 0.2)
response = Typhoeus::Response.new(:code => 301,:effective_url => 'https://foobar.com', :headers_hash => {"Location" => person.receive_url.sub('http://', 'https://')}, :body => "", :time => 0.2)
@hydra.stub(:post, person.receive_url).and_return(response)
Typhoeus::Hydra.stub!(:new).and_return(@hydra)
......
require 'spec_helper'
describe Pod do
it 'has many pod_stats' do
Pod.new.pod_stats.should be_empty
end
describe '.find_or_create_by_url' do
it 'takes a url, and makes one by host' do
pod = Pod.find_or_create_by_url('https://joindiaspora.com/maxwell')
pod.host.should == 'joindiaspora.com'
end
it 'sets ssl boolean(side-effect)' do
pod = Pod.find_or_create_by_url('https://joindiaspora.com/maxwell')
pod.ssl.should be_true
end
end
end
require 'spec_helper'
describe PodStat do
pending "add some examples to (or delete) #{__FILE__}"
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