Skip to content
Permalink
Browse files

Add job-queue by using delayed_job

  • Loading branch information
akagisho committed Oct 11, 2013
1 parent e296305 commit 8808e5a7e39c7468298a1bfbb191af3adfe01210
@@ -12,4 +12,5 @@

# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
!/tmp/.gitkeep
/tmp/*
@@ -41,3 +41,5 @@ gem 'jquery-rails'
# gem 'debugger'

gem 'kaminari'
gem 'delayed_job_active_record'
gem 'daemons'
@@ -38,6 +38,12 @@ GEM
execjs
coffee-script-source (1.6.3)
commonjs (0.2.7)
daemons (1.1.9)
delayed_job (4.0.0)
activesupport (>= 3.0, < 4.1)
delayed_job_active_record (4.0.0)
activerecord (>= 3.0, < 4.1)
delayed_job (>= 3.0, < 4.1)
erubis (2.7.0)
execjs (2.0.2)
hike (1.2.3)
@@ -122,6 +128,8 @@ PLATFORMS

DEPENDENCIES
coffee-rails (~> 3.2.1)
daemons
delayed_job_active_record
jquery-rails
kaminari
less-rails
@@ -44,7 +44,7 @@ def create

respond_to do |format|
if @certificate.save
@certificate.update_expiration
@certificate.delay.update_expiration
format.html { redirect_to @certificate, notice: 'Certificate was successfully created.' }
format.json { render json: @certificate, status: :created, location: @certificate }
else
@@ -61,7 +61,7 @@ def update

respond_to do |format|
if @certificate.update_attributes(params[:certificate])
@certificate.update_expiration
@certificate.delay.update_expiration
format.html { redirect_to @certificate, notice: 'Certificate was successfully updated.' }
format.json { head :no_content }
else
@@ -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
@@ -26,4 +26,20 @@
t.datetime "updated_at", :null => false
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", :null => false
t.datetime "updated_at", :null => false
end

add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"

end
@@ -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 changes.

0 comments on commit 8808e5a

Please sign in to comment.
You can’t perform that action at this time.