Skip to content

Commit

Permalink
DelayedJob migration generator
Browse files Browse the repository at this point in the history
  • Loading branch information
andersondias committed Dec 22, 2009
1 parent e8a31c8 commit cf24701
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.textile
Expand Up @@ -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|
Expand Down
Binary file not shown.
@@ -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
Binary file not shown.
22 changes: 22 additions & 0 deletions 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

0 comments on commit cf24701

Please sign in to comment.