Skip to content
Browse files

Use Delayed::Job for background processing. Close #105.

  • Loading branch information...
1 parent baf0c95 commit f1d40903ea7ce7c081930a3b633618827b5a4f22 @bamnet bamnet committed Jul 18, 2012
Showing with 53 additions and 1 deletion.
  1. +3 −0 Gemfile
  2. +6 −0 Gemfile.lock
  3. +22 −0 db/migrate/20120719025622_create_delayed_jobs.rb
  4. +17 −1 db/schema.rb
  5. +5 −0 script/delayed_job
View
3 Gemfile
@@ -44,6 +44,9 @@ gem 'cancan'
gem 'jquery-tools'
+# Process jobs in the background
+gem 'delayed_job_active_record'
+
# Test Coverage
gem 'simplecov', :require => false, :group => :test
View
6 Gemfile.lock
@@ -40,6 +40,11 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.3.1)
+ delayed_job (3.0.0)
+ activesupport (~> 3.0)
+ delayed_job_active_record (0.3.1)
+ activerecord (> 2.1.0)
+ delayed_job (~> 3.0.0)
devise (2.0.4)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
@@ -124,6 +129,7 @@ DEPENDENCIES
attachable (>= 0.0.5)
cancan
coffee-rails (~> 3.2.1)
+ delayed_job_active_record
devise
jquery-rails
jquery-tools
View
22 db/migrate/20120719025622_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,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120715023358) do
+ActiveRecord::Schema.define(:version => 20120719025622) do
create_table "concerto_configs", :force => true do |t|
t.string "key"
@@ -51,6 +51,22 @@
t.string "type"
end
+ 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 "name"
t.text "description"
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

0 comments on commit f1d4090

Please sign in to comment.
Something went wrong with that request. Please try again.