resque / resque/resque-pool

Can't see postgresql tables when using mongoid

Open
#159 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
456
Forks
149
Avg merge
9d 7h
Merged PRs (30d)
3

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/tasks/resque.rake and reproduce the failure in a Resque job that queries the PostgreSQL-backed Admin model alongside a Mongoid model. Trace how the worker initializes ActiveRecord and Mongoid connections; done means the PostgreSQL table can be queried successfully from the job without the PG::UndefinedTable error.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, rails, ruby
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.