Skip to content

Commit

Permalink
Add delayed_jobs process.
Browse files Browse the repository at this point in the history
  • Loading branch information
rustyio committed Dec 7, 2014
1 parent 4837af2 commit 53cab78
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Procfile
@@ -1,2 +1,3 @@
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
imap_client: rake imap:client
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker: env QUEUE=worker bundle exec rake jobs:work
imap_client: bundle exec rake imap:client
5 changes: 5 additions & 0 deletions 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
22 changes: 22 additions & 0 deletions db/migrate/20141207200312_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
18 changes: 17 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20141207191800) do
ActiveRecord::Schema.define(version: 20141207200312) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -50,6 +50,22 @@
add_index "admin_users", ["email"], name: "index_admin_users_on_email", unique: true, using: :btree
add_index "admin_users", ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true, using: :btree

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", using: :btree

create_table "imap_daemon_heartbeats", force: true do |t|
t.string "tag"
t.datetime "created_at"
Expand Down

0 comments on commit 53cab78

Please sign in to comment.