]> git.openstreetmap.org Git - rails.git/blob - db/migrate/20181031113522_create_delayed_jobs.rb
Merge pull request #5932 from tomhughes/frozen-strings
[rails.git] / db / migrate / 20181031113522_create_delayed_jobs.rb
1 # frozen_string_literal: true
2
3 class CreateDelayedJobs < ActiveRecord::Migration[5.2]
4   def self.up
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
16     end
17
18     add_index :delayed_jobs, [:priority, :run_at], :name => "delayed_jobs_priority"
19   end
20
21   def self.down
22     drop_table :delayed_jobs
23   end
24 end