Im using a rails multitenant app with sidekiq. I add it apartment-sidekiq so it runs the jobs in the background with redis. My problem is that when i run MyWorker on the rails c I get this error:
WARN: Apartment::TenantNotFound: One of the following schema(s) is invalid: "companydemo" "public".
or if I try to query "User.last" inside the worker, I get the PG::UndefinedTable: ERROR: relation "public.users" does not exist.
my gemset
gem 'apartment', '~> 1.0', '>= 1.0.2'
gem 'sidekiq', '~> 4.0', '>= 4.1'
gem 'apartment-sidekiq', '~> 0.2.0'
procfile
web: bundle exec puma -C config/puma.rb
log: tail -f log/development.log
redis_s: redis-server
worker: bundle exec sidekiq -e production -C ./config/sidekiq.yml
I setup a simple worker to see the results.
class MyWorker
include Sidekiq::Worker
def perform(tenant)
puts "------------------------"
puts "------------------------"
puts "Tenant #{tenant}"
puts "Current Tenant #{Apartment::Tenant.current}"
puts "------------------------"
puts "------------------------"
end
end
more details here: gist detail, my sidekiq post, my apartment-sidekiq post
Update
running rake middleware
I found that apartment-sidekiq is not running on the middleware.
use Rack::Sendfile
use ActionDispatch::Static
use Rack::Lock
use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007febcb0e51f0>
use Rack::Runtime
use Rack::MethodOverride
use ActionDispatch::RequestId
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use MetaRequest::Middlewares::Headers
use WebConsole::Middleware
use ActionDispatch::DebugExceptions
use BetterErrors::Middleware
use Raygun::Middleware::RackExceptionInterceptor
use Raygun::Middleware::RailsInsertAffectedUser
use ActionDispatch::RemoteIp
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActiveRecord::Migration::CheckPending
use ActiveRecord::ConnectionAdapters::ConnectionManagement
use ActiveRecord::QueryCache
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
use ActionDispatch::Flash
use ActionDispatch::ParamsParser
use Rack::Head
use Rack::ConditionalGet
use Rack::ETag
use Apartment::Elevators::Subdomain
use Warden::Manager
use Apartment::Reloader
use JQuery::FileUpload::Rails::Middleware
use MetaRequest::Middlewares::MetaRequestHandler
use MetaRequest::Middlewares::AppRequestHandler
use Bullet::Rack
use Apartment::Elevators::Subdomain
use RecurringSelectMiddleware
run App::Application.routes
Update soluction was using on the procfile sidekiq with -e production.