Save the errors in a table and make it viewable in the ui

This commit is contained in:
Aaron Mueller 2013-01-10 21:33:21 +01:00
parent ad247f6dce
commit 04fa99b1f8
10 changed files with 79 additions and 7 deletions

View File

@ -13,3 +13,8 @@ $(document).ready ->
false
)
$(".delete_feed").on("ajax:success", (event, data) ->
$(this).parent().remove()
false
)

View File

@ -15,6 +15,16 @@ class FeedsController < ApplicationController
redirect_to :action => :index, :notice => "Add the feed"
end
def destroy
Feed.find(params[:id]).destroy
render :nothing => true, :status => :ok
end
def errors
@errors = Feed.find(params[:id]).errors
render :layout => false
end
def import
fh = File.open(Rails.root.join("public", "uploads", params[:importer][:import_file].original_filename))
# TODO: Hier gehts weiter

3
app/models/error.rb Normal file
View File

@ -0,0 +1,3 @@
class Error < ActiveRecord::Base
belongs_to :feed
end

View File

@ -1,7 +1,8 @@
require "pp"
class Feed < ActiveRecord::Base
has_many :items
has_many :items, :dependent => :destroy
has_many :errors, :dependent => :destroy
validates_uniqueness_of :url
@ -20,11 +21,19 @@ class Feed < ActiveRecord::Base
end
by_url(url).update_attribute(:has_errors, false)
rescue Exception => e
pp e
Error.create!(:feed_id => self.id, :action => :fetch_and_parse,
:message => e)
end
end,
:on_failure => lambda do |url, response_code, response_header, response_body|
by_url(url).update_attribute(:has_errors, true)
Error.create!(:feed_id => self.id, :action => :fetch_and_parse,
:message => "
url: #{url}
response-code: #{response_code}
response-header: #{response_header}
response-body: #{response_body}
")
end
)
end
@ -36,7 +45,15 @@ class Feed < ActiveRecord::Base
end,
:on_failure => lambda do |url, response_code, response_header, response_body|
if params.first.include?(:force)
Feed.create!(:url => url, :has_errors => true)
feed = Feed.create!(:url => url, :has_errors => true)
Error.create!(:feed_id => feed.id, :action => :import,
:message => "
url: #{url}
response-code: #{response_code}
response-header: #{response_header}
response-body: #{response_body}
")
end
end
)

View File

@ -1,5 +1,9 @@
<ul id="feed_list">
<% @feeds.each do |feed| %>
<li><%= link_to feed.title, feed_path(feed), :remote => true, :update => "feed_content" %></li>
<li>
(<%= link_to "del", feed_path(feed), :remote => true, :method => :delete, :class => "delete_feed button", :confirm => "Delete this feed?" %>,
<%= link_to "err", errors_feed_path(feed), :remote => true, :class => "button", :update => "feed_content" %>)
<%= link_to feed.title, feed_path(feed), :remote => true, :update => "feed_content" %>
</li>
<% end %>
</ul>
</ul>

View File

@ -0,0 +1,6 @@
<% @errors.each do |error| %>
<div class="error-box">
<strong><%= error.type %></strong>
<pre><%= error.message %></pre>
</div>
<% end %>

View File

@ -14,7 +14,10 @@ FeedFu::Application.routes.draw do
# resources :products
resources :feeds do
collection do
get "import"
get :import
end
member do
get :errors
end
end

View File

@ -0,0 +1,11 @@
class CreateErrors < ActiveRecord::Migration
def change
create_table :errors do |t|
t.references :feed
t.string :action, :default => :undefined
t.text :message, :default => "no message"
t.timestamps
end
end
end

View File

@ -11,7 +11,15 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120407180851) do
ActiveRecord::Schema.define(:version => 20130110200633) do
create_table "errors", :force => true do |t|
t.integer "feed_id"
t.string "action", :default => "undefined"
t.text "message", :default => "no message"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "feeds", :force => true do |t|
t.string "url"

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe Errors do
pending "add some examples to (or delete) #{__FILE__}"
end