0

I have been trying to run a migration based on the following database.yml

database.yml:

development:
  adapter: postgresql
  encoding: utf8
  database: test_development
  timeout: 5000
  queue:
    adapter: postgresql
    encoding: utf8
    database: test_queue_development
    timeout: 5000

What I want to do is to create a table "delayed_jobs" in test_queue_development database. Unfortuanately, the table gets created in test_development. The initializer for delayed_job.rb is the following.

config/initiallizers/delayed_job.rb:

db_queue_config = ActiveRecord::Base.configurations[Rails.env]['queue']
if db_queue_config
  Delayed::Backend::ActiveRecord::Job.establish_connection(db_queue_config)
end

I am running the migration only in development

The migration should respect Delayed::Backend::ActiveRecord::Job.connection and create the table in test_queue_development but it always creates the table in test_development.

db/migrate/create_delayed_jobs.rb

class CreateDelayedJobs < ActiveRecord::Migration
  def self.connection
    Delayed::Backend::ActiveRecord::Job.connection
  end

  def self.up
    create_table :delayed_jobs do |table|
      # Allows some jobs to jump to the front of the queue
      table.integer :priority, :default => 0
      # Provides for retries, but still fail eventually.
      table.integer :attempts, :default => 0
      # YAML-encoded string of the object that will do work
      table.text :handler, :limit => 500.kilobytes
      # reason for last failure (See Note below)
      table.text :last_error
      # The queue that this job is in
      table.string :queue, :default => nil
      # When to run.
      # Could be Time.zone.now for immediately, or sometime in the future.
      table.datetime :run_at
      # Set when a client is working on this object
      table.datetime :locked_at
      # Set when all retries have failed
      table.datetime :failed_at
      # Who is working on this object (if locked)
      table.string :locked_by

      table.timestamps
    end

    add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority'
    add_index :delayed_jobs, [:queue], :name => 'delayed_jobs_queue'
  end

My question is: How can I introduce extra debugging into the migration so I can see what's going wrong? If i get into the rails console and type:

Delayed::Backend::ActiveRecord::Job.connection

i get info related to the queue database, which means self.connection runs fine and the initializer worked as expected. The code samples were take from canvas-lms

Thank you.

Nick_K
  • 541
  • 6
  • 22

0 Answers0