From c282f6c14e8cc1bf97609f3647ead96c2c285692 Mon Sep 17 00:00:00 2001 From: Gopesh Tulsyan Date: Sun, 20 Jul 2014 07:48:03 +0530 Subject: [PATCH] Delayed job integration done --- Gemfile | 1 + Gemfile.lock | 6 +++ bin/delayed_job | 5 +++ config/boot.rb | 3 +- .../20140719160903_create_delayed_jobs.rb | 22 ++++++++++ db/schema.rb | 40 +++++++++++++------ 6 files changed, 64 insertions(+), 13 deletions(-) create mode 100755 bin/delayed_job create mode 100644 db/migrate/20140719160903_create_delayed_jobs.rb diff --git a/Gemfile b/Gemfile index ed5ba3a5..b624bc4c 100644 --- a/Gemfile +++ b/Gemfile @@ -91,6 +91,7 @@ gem 'rdoc-generator-fivefish' # We use factory_girl for seeds gem 'factory_girl_rails' +gem 'delayed_job_active_record' # We use ahoy for visitor tracking gem 'ahoy_matey' gem 'activeuuid' diff --git a/Gemfile.lock b/Gemfile.lock index 181a1c20..5b172176 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -104,6 +104,11 @@ GEM railties (>= 3.1.0) database_cleaner (1.3.0) debugger-linecache (1.2.0) + delayed_job (4.0.2) + activesupport (>= 3.0, < 4.2) + delayed_job_active_record (4.0.1) + activerecord (>= 3.0, < 4.2) + delayed_job (>= 3.0, < 4.1) devise (3.2.4) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -406,6 +411,7 @@ DEPENDENCIES coveralls d3_rails database_cleaner + delayed_job_active_record devise factory_girl_rails font-awesome-rails diff --git a/bin/delayed_job b/bin/delayed_job new file mode 100755 index 00000000..edf19598 --- /dev/null +++ b/bin/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 diff --git a/config/boot.rb b/config/boot.rb index f2830ae3..d2a5e451 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,5 +1,6 @@ require 'rubygems' - +require 'yaml' +YAML::ENGINE.yamler = 'syck' # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) diff --git a/db/migrate/20140719160903_create_delayed_jobs.rb b/db/migrate/20140719160903_create_delayed_jobs.rb new file mode 100644 index 00000000..ee7515c2 --- /dev/null +++ b/db/migrate/20140719160903_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, null: false # Allows some jobs to jump to the front of the queue + table.integer :attempts, default: 0, null: false # Provides for retries, but still fail eventually. + table.text :handler, null: false # 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 diff --git a/db/schema.rb b/db/schema.rb index 4a31463d..781e9871 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140716115448) do +ActiveRecord::Schema.define(version: 20140719160903) do create_table "ahoy_events", force: true do |t| t.uuid "visit_id" @@ -21,9 +21,9 @@ ActiveRecord::Schema.define(version: 20140716115448) do t.datetime "time" end - add_index "ahoy_events", ["time"], name: "index_ahoy_events_on_time", using: :btree - add_index "ahoy_events", ["user_id"], name: "index_ahoy_events_on_user_id", using: :btree - add_index "ahoy_events", ["visit_id"], name: "index_ahoy_events_on_visit_id", using: :btree + add_index "ahoy_events", ["time"], name: "index_ahoy_events_on_time" + add_index "ahoy_events", ["user_id"], name: "index_ahoy_events_on_user_id" + add_index "ahoy_events", ["visit_id"], name: "index_ahoy_events_on_visit_id" create_table "answers", force: true do |t| t.string "title" @@ -70,9 +70,9 @@ ActiveRecord::Schema.define(version: 20140716115448) do t.integer "rgt" end - add_index "comments", ["commentable_id"], name: "index_comments_on_commentable_id", using: :btree - add_index "comments", ["commentable_type"], name: "index_comments_on_commentable_type", using: :btree - add_index "comments", ["user_id"], name: "index_comments_on_user_id", using: :btree + add_index "comments", ["commentable_id"], name: "index_comments_on_commentable_id" + add_index "comments", ["commentable_type"], name: "index_comments_on_commentable_type" + add_index "comments", ["user_id"], name: "index_comments_on_user_id" create_table "conferences", force: true do |t| t.string "guid", null: false @@ -133,6 +133,22 @@ ActiveRecord::Schema.define(version: 20140716115448) do t.integer "question_id" end + create_table "delayed_jobs", force: true do |t| + t.integer "priority", default: 0, null: false + t.integer "attempts", default: 0, null: false + t.text "handler", null: false + 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" + t.datetime "updated_at" + end + + add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority" + create_table "dietary_choices", force: true do |t| t.integer "conference_id" t.string "title", null: false @@ -446,9 +462,9 @@ ActiveRecord::Schema.define(version: 20140716115448) do t.text "volunteer_experience" end - add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree - add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree - add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree + add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true + add_index "users", ["email"], name: "index_users_on_email", unique: true + add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true create_table "vchoices", force: true do |t| t.integer "vday_id" @@ -491,7 +507,7 @@ ActiveRecord::Schema.define(version: 20140716115448) do t.datetime "created_at" end - add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id", using: :btree + add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id" create_table "visits", force: true do |t| t.uuid "visitor_id" @@ -516,7 +532,7 @@ ActiveRecord::Schema.define(version: 20140716115448) do t.datetime "started_at" end - add_index "visits", ["user_id"], name: "index_visits_on_user_id", using: :btree + add_index "visits", ["user_id"], name: "index_visits_on_user_id" create_table "votes", force: true do |t| t.integer "event_id"