Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

DelayedJob migration generator

  • Loading branch information...
commit cf24701cc4941e483c8c78cb64b7bb5c6c7ed29e 1 parent e8a31c8
@andersondias andersondias authored
View
7 README.textile
@@ -14,7 +14,12 @@ It is a direct extraction from Shopify where the job table is responsible for a
h2. Setup
-The library evolves around a delayed_jobs table which looks as follows:
+The library evolves around a delayed_jobs table which can be created by using:
+<pre><code>
+ script/generate delayed_job_migration
+</code></pre>
+
+The created table looks as follows:
<pre><code>
create_table :delayed_jobs, :force => true do |table|
View
BIN  generators/delayed_job_migration/.delayed_job_migration_generator.rb.swp
Binary file not shown
View
15 generators/delayed_job_migration/delayed_job_migration_generator.rb
@@ -0,0 +1,15 @@
+class DelayedJobMigrationGenerator < Rails::Generator::Base
+ def manifest
+ record do |m|
+ options = {
+ :migration_file_name => 'create_delayed_jobs'
+ }
+
+ m.migration_template 'migration.rb', 'db/migrate', options
+ end
+ end
+
+ def banner
+ "Usage: #{$0} #{spec.name}"
+ end
+end
View
BIN  generators/delayed_job_migration/templates/.migration.rb.swp
Binary file not shown
View
22 generators/delayed_job_migration/templates/migration.rb
@@ -0,0 +1,22 @@
+class CreateDelayedJobs < ActiveRecord::Migration
+ def self.up
+ create_table :delayed_jobs, :force => true do |t|
+ t.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
+ t.integer :attempts, :default => 0 # Provides for retries, but still fail eventually.
+ t.text :handler # YAML-encoded string of the object that will do work
+ t.string :last_error # reason for last failure (See Note below)
+ t.datetime :run_at # When to run. Could be Time.now for immediately, or sometime in the future.
+ t.datetime :locked_at # Set when a client is working on this object
+ t.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
+ t.string :locked_by # Who is working on this object (if locked)
+
+ t.timestamps
+ end
+
+ add_index :delayed_jobs, :locked_by
+ end
+
+ def self.down
+ drop_table :delayed_jobs
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.