Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: cocoa/qfeedreader
base: cd4fb5090e
...
head fork: cocoa/qfeedreader
compare: 6af130079a
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
3  Gemfile
@@ -8,7 +8,8 @@ gem 'rails', '3.2.8'
gem 'sqlite3'
gem 'feedzirra'
gem 'feedbag'
-
+gem 'delayed_job_active_record'
+gem 'daemons'
# Gems used only for assets and not required
# in production environments by default.
View
8 Gemfile.lock
@@ -38,6 +38,12 @@ GEM
execjs
coffee-script-source (1.4.0)
curb (0.8.1)
+ daemons (1.0.10)
+ delayed_job (3.0.2)
+ activesupport (~> 3.0)
+ delayed_job_active_record (0.3.2)
+ activerecord (> 2.1.0)
+ delayed_job (~> 3.0.0)
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
@@ -118,6 +124,8 @@ PLATFORMS
DEPENDENCIES
coffee-rails (~> 3.2.1)
+ daemons
+ delayed_job_active_record
feedbag
feedzirra
jquery-rails
View
11 app/controllers/feeds_controller.rb
@@ -16,6 +16,7 @@ def destroy
# - - - - - - - - - - - - -
+=begin
def refresh
if params[:id]
Feed.find(params[:id]).fetch
@@ -24,5 +25,15 @@ def refresh
end
redirect_to :action => :index
end
+=end
+
+ def refresh
+ if params[:id]
+ Feed.fetch(params[:id])
+ else
+ Feed.fetch_all
+ end
+ redirect_to :action => :index
+ end
end
View
39 app/models/feed.rb
@@ -7,8 +7,46 @@ class Feed < ActiveRecord::Base
after_create :fetch
+ def fetch
+ feed_url = Feedbag.find self.url
+ feed = Feedzirra::Feed.fetch_and_parse feed_url.first
+
+ transaction do
+ self.title = feed.title
+ self.touch
+ save!
+
+ feed.entries.each do |entry|
+ unless posts.find_by_url entry.url
+ posts.create! :title => entry.title, :url => entry.url
+ end
+ end
+ end
+ end
+ handle_asynchronously :fetch
+
+ def self.fetch(id)
+ find(id).fetch
+ end
+
+
+ def self.fetch_all
+ all.each do |feed|
+ feed.fetch
+ # Feed.delay.fetch(feed.id) # convierte (1 tarea de tiempo N) en (N tareas de tiempo 1)
+ end
+ end
+
+
+
+=begin
def fetch
+ Delayed::Job.enqueue self
+ end
+
+
+ def perform
feed_url = Feedbag.find self.url
feed = Feedzirra::Feed.fetch_and_parse feed_url.first
@@ -32,6 +70,7 @@ def self.fetch_all
feed.fetch
end
end
+=end
end
View
6 app/views/feeds/index.html.erb
@@ -1,4 +1,4 @@
-<h1>Feed Reader - no queueing</h1>
+<h1>Queueing Feed Reader</h1>
<%= form_tag feeds_path, :method => :post do %>
<%= label_tag 'Add a feed' %>
@@ -23,7 +23,7 @@
<%= link_to 'destroy', feed_path(feed.id), :method => :delete %>
</h3>
- <% feed.posts.each do |post| %>
- <%= link_to post.title, post.url %> *
+ <% feed.posts.order('created_at DESC').first(6).each do |post| %>
+ <%= link_to post.title, post.url %>, created <%= time_ago_in_words post.created_at %> ago *
<%end%>
<%end%>
View
22 db/migrate/20121103205829_create_delayed_jobs.rb
@@ -0,0 +1,22 @@
+class CreateDelayedJobs < ActiveRecord::Migration
+ def self.up
+ create_table :delayed_jobs, :force => true do |table|
+ table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
+ table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually.
+ table.text :handler # YAML-encoded string of the object that will do work
+ table.text :last_error # reason for last failure (See Note below)
+ table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
+ table.datetime :locked_at # Set when a client is working on this object
+ table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
+ table.string :locked_by # Who is working on this object (if locked)
+ table.string :queue # The name of the queue this job is in
+ table.timestamps
+ end
+
+ add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority'
+ end
+
+ def self.down
+ drop_table :delayed_jobs
+ end
+end
View
18 db/schema.rb
@@ -11,7 +11,23 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20121102205938) do
+ActiveRecord::Schema.define(:version => 20121103205829) do
+
+ create_table "delayed_jobs", :force => true do |t|
+ t.integer "priority", :default => 0
+ t.integer "attempts", :default => 0
+ t.text "handler"
+ t.text "last_error"
+ t.datetime "run_at"
+ t.datetime "locked_at"
+ t.datetime "failed_at"
+ t.string "locked_by"
+ t.string "queue"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
create_table "feeds", :force => true do |t|
t.string "title", :default => "(pending)"
View
5 script/delayed_job
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
+require 'delayed/command'
+Delayed::Command.new(ARGV).daemonize

No commit comments for this range

Something went wrong with that request. Please try again.