Permalink
Browse files

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

  • Loading branch information...
1 parent 7956eb7 commit bb8db654d6330c099b3dae735df2355d0f4d8a7e @maxwell maxwell committed Jul 30, 2011
View
@@ -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
View
@@ -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
View
@@ -0,0 +1,20 @@
+# 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 @@ def self.perform(user_id, enc_object_xml, person_ids, retry_count=0)
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
View
@@ -0,0 +1,13 @@
+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)
@rsofaer
rsofaer Jul 31, 2011 Member

This will break on pods with port numbers, including in the multi_server specs.

+ unless pod.persisted?
+ pod.ssl = (u.scheme == 'https')? true : false
+ pod.save
+ end
+ pod
+ end
+end
@@ -0,0 +1,4 @@
+class PodStat < ActiveRecord::Base
+ belongs_to :pod
+
+end
View
@@ -1,15 +0,0 @@
-# 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
@@ -0,0 +1,14 @@
+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
@@ -0,0 +1,16 @@
+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
View
@@ -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 @@
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"
View
@@ -63,3 +63,4 @@
time_interval += 1000
end
end
+puts "successfully seed the db with users eve, bob, and alice (password: 'evankorth')"
@@ -14,8 +14,8 @@
@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 @@
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)
@@ -0,0 +1,19 @@
+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
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe PodStat do
+ pending "add some examples to (or delete) #{__FILE__}"
+end

0 comments on commit bb8db65

Please sign in to comment.