Skip to content

Can't see postgresql tables when using mongoid #159

@alfredoreduarte

Description

@alfredoreduarte

Hi! I'm using mongoid alongside postgresql in a rails 5 app.

My resque jobs work perfectly with the mongoid models, however, whenever I try to use one of my postgresql tables inside a job, I get the following error:

PG::UndefinedTable: ERROR: relation "admins" does not exist LINE 1: SELECT "admins".* FROM "admins" ^ : SELECT "admins".* FROM "admins"

This is my lib/tasks/resque.rake file

require 'resque/tasks'

task "resque:setup" => :environment do
	ENV['QUEUE'] = '*'
	Resque.before_fork do
    defined?(ActiveRecord::Base) and
      ActiveRecord::Base.connection.disconnect!
  end

  Resque.after_fork do
    defined?(ActiveRecord::Base) and
      ActiveRecord::Base.establish_connection
  end
end

The postgres table mentioned does exist, and works perfectly with the rails app. It seems like, at least outside of the main rails app, ActiveRecord defaults to using mongoid, so none of my postgresql models are visible inside the worker.

Am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions