1 # frozen_string_literal: true
 
   3 class CreateDelayedJobs < ActiveRecord::Migration[5.2]
 
   5     create_table :delayed_jobs, :force => true do |table|
 
   6       table.integer :priority, :default => 0, :null => false # Allows some jobs to jump to the front of the queue
 
   7       table.integer :attempts, :default => 0, :null => false # Provides for retries, but still fail eventually.
 
   8       table.text :handler,                    :null => false # YAML-encoded string of the object that will do work
 
   9       table.text :last_error                                 # reason for last failure (See Note below)
 
  10       table.datetime :run_at                                 # When to run. Could be Time.zone.now for immediately, or sometime in the future.
 
  11       table.datetime :locked_at                              # Set when a client is working on this object
 
  12       table.datetime :failed_at                              # Set when all retries have failed (actually, by default, the record is deleted instead)
 
  13       table.string :locked_by                                # Who is working on this object (if locked)
 
  14       table.string :queue                                    # The name of the queue this job is in
 
  15       table.timestamps :null => true
 
  18     add_index :delayed_jobs, [:priority, :run_at], :name => "delayed_jobs_priority"
 
  22     drop_table :delayed_jobs