Skip to content
Snippets Groups Projects
Commit 4d1c93d9 authored by danielgrippi's avatar danielgrippi
Browse files

Removed , but not the table. Record all in httpmulti success

parent 0dfcbca5
No related branches found
No related tags found
No related merge requests found
...@@ -37,6 +37,9 @@ module Job ...@@ -37,6 +37,9 @@ module Job
request = Request.new(url, OPTS.merge(:params => {:xml => CGI::escape(xml)})) request = Request.new(url, OPTS.merge(:params => {:xml => CGI::escape(xml)}))
request.on_complete do |response| request.on_complete do |response|
# Save the reference to the pod to the database if not already present
Pod.find_or_create_by_url(response.effective_url)
if response.code >= 300 && response.code < 400 if response.code >= 300 && response.code < 400
if response.headers_hash['Location'] == response.request.url.sub('http://', 'https://') if response.headers_hash['Location'] == response.request.url.sub('http://', 'https://')
location = URI.parse(response.headers_hash['Location']) location = URI.parse(response.headers_hash['Location'])
...@@ -48,10 +51,7 @@ module Job ...@@ -48,10 +51,7 @@ module Job
end end
end end
unless response.success? unless response.success?
pod = Pod.find_or_create_by_url(response.effective_url) Rails.logger.info("event=http_multi_fail sender_id=#{user_id} recipient_id=#{person.id} url=#{response.effective_url} response_code='#{response.code}'")
log_line = "event=http_multi_fail sender_id=#{user_id} recipient_id=#{person.id} url=#{response.effective_url} response_code='#{response.code}'"
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 failed_request_people << person.id
end end
end end
......
class Pod < ActiveRecord::Base class Pod < ActiveRecord::Base
has_many :pod_stats
def self.find_or_create_by_url(url) def self.find_or_create_by_url(url)
u = URI.parse(url) u = URI.parse(url)
pod = self.find_or_initialize_by_host(u.host) pod = self.find_or_initialize_by_host(u.host)
......
class PodStat < ActiveRecord::Base
belongs_to :pod
end
class RemovePodStatsTable < ActiveRecord::Migration
def self.up
drop_table :pod_stats
end
def self.down
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
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110818212541) do ActiveRecord::Schema.define(:version => 20110830170929) do
create_table "aspect_memberships", :force => true do |t| create_table "aspect_memberships", :force => true do |t|
t.integer "aspect_id", :null => false t.integer "aspect_id", :null => false
...@@ -236,15 +236,6 @@ ActiveRecord::Schema.define(:version => 20110818212541) do ...@@ -236,15 +236,6 @@ ActiveRecord::Schema.define(:version => 20110818212541) do
add_index "people", ["guid"], :name => "index_people_on_guid", :unique => true add_index "people", ["guid"], :name => "index_people_on_guid", :unique => true
add_index "people", ["owner_id"], :name => "index_people_on_owner_id", :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| create_table "pods", :force => true do |t|
t.string "host" t.string "host"
t.boolean "ssl" t.boolean "ssl"
......
require 'spec_helper' require 'spec_helper'
describe Pod do describe Pod do
it 'has many pod_stats' do
Pod.new.pod_stats.should be_empty
end
describe '.find_or_create_by_url' do describe '.find_or_create_by_url' do
it 'takes a url, and makes one by host' do it 'takes a url, and makes one by host' do
pod = Pod.find_or_create_by_url('https://joindiaspora.com/maxwell') pod = Pod.find_or_create_by_url('https://joindiaspora.com/maxwell')
......
require 'spec_helper'
describe PodStat do
pending "add some examples to (or delete) #{__FILE__}"
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment