Skip to content

Commit

Permalink
queue jobs with minion and rabbitmq
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Wiggins committed Sep 13, 2009
1 parent aa30501 commit e965803
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/controllers/feeds_controller.rb
Expand Up @@ -16,7 +16,7 @@ def show
end

def create
feed = Feed.create! :url => params[:url]
Feed.enqueue(params[:url])
redirect_to :action => :index
end

Expand Down
10 changes: 9 additions & 1 deletion app/models/feed.rb
Expand Up @@ -3,8 +3,12 @@ class Feed < ActiveRecord::Base

after_create :fetch

def self.enqueue(url)
Minion.enqueue('feed.fetch', :url => url)
end

def fetch
Delayed::Job.enqueue self
self.class.enqueue(url)
end

def perform
Expand All @@ -28,4 +32,8 @@ def self.fetch_all
feed.fetch
end
end

def self.find_or_new(url)
find_by_url(url) || Feed.new(:url => url)
end
end
15 changes: 1 addition & 14 deletions db/schema.rb
Expand Up @@ -9,20 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20090412203342) do

create_table "delayed_jobs", :force => true do |t|
t.integer "priority", :default => 0
t.integer "attempts", :default => 0
t.text "handler"
t.string "last_error"
t.datetime "run_at"
t.datetime "locked_at"
t.datetime "failed_at"
t.string "locked_by"
t.datetime "created_at"
t.datetime "updated_at"
end
ActiveRecord::Schema.define(:version => 20090411033334) do

create_table "feeds", :force => true do |t|
t.string "url"
Expand Down
9 changes: 9 additions & 0 deletions worker.rb
@@ -0,0 +1,9 @@
require File.dirname(__FILE__) + '/config/environment'

include Minion

job 'feed.fetch' do |args|
feed = Feed.find_or_new(args['url'])
feed.perform
end

0 comments on commit e965803

Please sign in to comment.