influitive / apartment-sidekiq Goto Github PK
View Code? Open in Web Editor NEWSidekiq support for the Apartment Gem
License: MIT License
Sidekiq support for the Apartment Gem
License: MIT License
Here's my scenario:
Then I run a sidekiq job which throws NPE.
The middleware chain is executed, Sidekiq::Middleware::Server::ActiveRecord
runs ::ActiveRecord::Base.clear_active_connections!
, then Apartment::Sidekiq::Middleware::Server
tried to switch
Then another exception is thrown ActiveRecord::ConnectionTimeoutError: could not obtain a database connection within 5.000 seconds (waited 5.000 seconds)
because there is no connection for apartment to reset and I also see there are 3 connections now instead of 2. The third cannot be reaped and is a zombie thread just sleeping from what I can tell.
I've found that if I simply re-order the middleware chain like so:
# line 24 of /lib/apartment/sidekiq.rb
chain.insert_after ::Sidekiq::Middleware::Server::ActiveRecord, Apartment::Sidekiq::Middleware::Server
Then the exception throws and we switch!
before Sidekiq::Middleware::Server::ActiveRecord
has cleaned up.
Is there a particular reason for the current ordering?
Hi,
We are currently using apartment-sidekiq and upgraded to rails 6.
Is it possible apartment-sidekiq will update the dependency on apartment
gem to support rails 6?
thank you.
We have 2 servers: master and a slave server. slave server is primarily being used to handle reports. All the long background running processes are pushed to the slave server. We are using sidekiq for background processing.
Now, whenever a report is ready we create a Download object in which the generated report is attached. As the process is running in slave we need to connect to master in order to create Download object. Code looks something like this:
def perform(tenant_name)
Apartment::Tenant.switch(tenant_name) do
# data processing code here....
connection = MasterDbConnectionService.connect(tenant_name)
Download.create!(time_taken: time_taken, file: file) # Pseudo code
# Disconnect from the previously established connection
MasterDbConnectionService.disconnect(connection)
end
end
But we are intermittently facing the error especially for long running jobs most probably because of sidekiq retrying that job.
ActiveRecord::ConnectionNotEstablished) "No connection pool with 'primary' found.
MasterDbConnectionService code:
def connect(tenant_name)
ActiveRecord::Base.establish_connection(master_config.merge(schema_search_path: "'#{tenant_name}',public,shared_extensions"))
end
Config: Nginx, Phusion Passenger, Postgres, ruby-2.3.1, rails 5.1.3
Full stack trace:
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activerecord-5.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:930:in `retrieve_connection'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activerecord-5.1.3/lib/active_record/connection_handling.rb:116:in `retrieve_connection'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activerecord-5.1.3/lib/active_record/connection_handling.rb:88:in `connection'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/apartment-2.1.0/lib/apartment/adapters/postgresql_adapter.rb:40:in `reset'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/apartment-2.1.0/lib/apartment/adapters/abstract_adapter.rb:88:in `rescue in ensure in switch'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/apartment-2.1.0/lib/apartment/adapters/abstract_adapter.rb:88:in `ensure in switch'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/apartment-2.1.0/lib/apartment/adapters/abstract_adapter.rb:88:in `switch'
/home/deployer/workspace/rails/dms_webapp/app/jobs/report_download_job.rb:12:in `perform'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activejob-5.1.3/lib/active_job/execution.rb:37:in `block in perform_now'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:108:in `block in run_callbacks'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/i18n-0.9.5/lib/i18n.rb:268:in `with_locale'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activejob-5.1.3/lib/active_job/translation.rb:7:in `block (2 levels) in <module:Translation>'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:117:in `instance_exec'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:117:in `block in run_callbacks'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activejob-5.1.3/lib/active_job/logging.rb:24:in `block (4 levels) in <module:Logging>'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/notifications.rb:166:in `block in instrument'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/notifications.rb:166:in `instrument'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activejob-5.1.3/lib/active_job/logging.rb:23:in `block (3 levels) in <module:Logging>'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activejob-5.1.3/lib/active_job/logging.rb:44:in `block in tag_logger'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/tagged_logging.rb:69:in `block in tagged'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/tagged_logging.rb:26:in `tagged'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/tagged_logging.rb:69:in `tagged'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activejob-5.1.3/lib/active_job/logging.rb:44:in `tag_logger'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activejob-5.1.3/lib/active_job/logging.rb:20:in `block (2 levels) in <module:Logging>'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:117:in `instance_exec'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:117:in `block in run_callbacks'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:135:in `run_callbacks'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activejob-5.1.3/lib/active_job/execution.rb:33:in `perform_now'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activejob-5.1.3/lib/active_job/execution.rb:22:in `block in execute'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:108:in `block in run_callbacks'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activejob-5.1.3/lib/active_job/railtie.rb:26:in `block (4 levels) in <class:Railtie>'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/execution_wrapper.rb:85:in `wrap'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/reloader.rb:68:in `block in wrap'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/execution_wrapper.rb:81:in `wrap'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/reloader.rb:67:in `wrap'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activejob-5.1.3/lib/active_job/railtie.rb:25:in `block (3 levels) in <class:Railtie>'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:117:in `instance_exec'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:117:in `block in run_callbacks'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:135:in `run_callbacks'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activejob-5.1.3/lib/active_job/execution.rb:20:in `execute'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activejob-5.1.3/lib/active_job/queue_adapters/sidekiq_adapter.rb:40:in `perform'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb:199:in `execute_job'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb:170:in `block (2 levels) in process'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/middleware/chain.rb:128:in `block in invoke'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/middleware/chain.rb:133:in `invoke'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb:169:in `block in process'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb:141:in `block (6 levels) in dispatch'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/job_retry.rb:97:in `local'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb:140:in `block (5 levels) in dispatch'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/rails.rb:42:in `block in call'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/execution_wrapper.rb:85:in `wrap'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/reloader.rb:68:in `block in wrap'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/execution_wrapper.rb:85:in `wrap'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/activesupport-5.1.3/lib/active_support/reloader.rb:67:in `wrap'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/rails.rb:41:in `call'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb:136:in `block (4 levels) in dispatch'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb:215:in `stats'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb:131:in `block (3 levels) in dispatch'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/job_logger.rb:7:in `call'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb:130:in `block (2 levels) in dispatch'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/job_retry.rb:72:in `global'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb:129:in `block in dispatch'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/logging.rb:44:in `with_context'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/logging.rb:38:in `with_job_hash_context'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb:128:in `dispatch'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb:168:in `process'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb:85:in `process_one'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/processor.rb:73:in `run'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/util.rb:16:in `watchdog'
/home/deployer/.rvm/gems/ruby-2.3.1@rails513/gems/sidekiq-5.0.4/lib/sidekiq/util.rb:25:in `block in safe_thread'
This gem has a dependency on apartment 1.x, but the apartment 2.0 gem was released last week.
Can we get a version bump so that this gem can be installed with the new version of apartment? We're running it just fine with the master
branch of apartment from 2017-08-24.
Does anyone have a recommended SQL query(ex: SELECT * FROM users
) for getting all users from all tenants?
More a question than a bug, but I'm curious if this gem has been tested with Sidekiq 4 yet? I bumped to 4 to see if it would work without issue, but unfortunately, I'm running into some issues. I'm wondering it might be related to the apartment-sidekiq gem (I can see it in the backtrace, but I think it might be just the trace, not actually originating from apartment-sidekiq) or if you might be able to say whether it's related to Sidekiq.
I posted a bug on Sidekiq's issues here: sidekiq/sidekiq#2769. The stack trace is in that bug.
When looking at the sidekiq web interface, you can only see the tenant of a certain job in the individual job details from the retries/scheduled/dead list. That makes it hard to identify a running or enqueued job.
I ended up adding a small monkey patch to show the tenant as one of the arguments in my apartment initializer, but don't know if that's the best approach or where would you place it in this gem.
module Sidekiq
module JobApartmentExtensions
def display_args
[@item['apartment']].compact + super
end
end
class Job
prepend JobApartmentExtensions
end
end
Hi I get this error whe I try to process a img in the background.
09:37:22 redis_s.1 | 33693:M 07 Dec 09:37:22.096 * 100 changes in 300 seconds. Saving...
09:37:22 redis_s.1 | 33693:M 07 Dec 09:37:22.097 * Background saving started by pid 71671
09:37:22 redis_s.1 | 71671:C 07 Dec 09:37:22.099 * DB saved on disk
09:37:22 redis_s.1 | 33693:M 07 Dec 09:37:22.197 * Background saving terminated with success
09:39:27 worker.1 | 2015-12-07T13:39:27.825Z 33694 TID-ougbxml30 DelayedPaperclip::Jobs::ActiveJob JID-9570d2fa326ad3b1bbc24651 INFO: start
09:39:28 worker.1 | 2015-12-07T13:39:28.299Z 33694 TID-ougbxml30 DelayedPaperclip::Jobs::ActiveJob JID-9570d2fa326ad3b1bbc24651 INFO: fail: 0.474 sec
09:39:28 worker.1 | 2015-12-07T13:39:28.300Z 33694 TID-ougbxml30 WARN: {"class"=>"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper", "wrapped"=>"DelayedPaperclip::Jobs::ActiveJob", "queue"=>"paperclip", "args"=>[{"job_class"=>"DelayedPaperclip::Jobs::ActiveJob", "job_id"=>"44d6026e-5aca-4a07-9d18-054e75bd0eb7", "queue_name"=>"paperclip", "arguments"=>["TaskTran", 449, "signature_manager"], "locale"=>"es"}], "retry"=>true, "jid"=>"9570d2fa326ad3b1bbc24651", "created_at"=>1449495208.7341068, "apartment"=>"companydemo", "enqueued_at"=>1449495567.8203, "error_message"=>"One of the following schema(s) is invalid: \"companydemo\" \"public\"", "error_class"=>"Apartment::TenantNotFound", "failed_at"=>1449495209.205343, "retry_count"=>4, "retried_at"=>1449495568.298719}
09:39:28 worker.1 | 2015-12-07T13:39:28.300Z 33694 TID-ougbxml30 WARN: Apartment::TenantNotFound: One of the following schema(s) is invalid: "companydemo" "public"
09:39:28 worker.1 | 2015-12-07T13:39:28.301Z 33694 TID-ougbxml30 WARN: /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/apartment-1.0.2/lib/apartment/adapters/postgresql_adapter.rb:92:in `rescue in connect_to_new'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/apartment-1.0.2/lib/apartment/adapters/postgresql_adapter.rb:85:in `connect_to_new'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/apartment-1.0.2/lib/apartment/adapters/abstract_adapter.rb:84:in `switch!'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/apartment-1.0.2/lib/apartment/adapters/abstract_adapter.rb:97:in `switch'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/apartment-sidekiq-0.2.0/lib/apartment/sidekiq/middleware/server.rb:4:in `call'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/server/active_record.rb:6:in `call'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/server/retry_jobs.rb:74:in `call'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/server/logging.rb:11:in `block in call'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/logging.rb:30:in `with_context'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/server/logging.rb:7:in `call'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/chain.rb:132:in `call'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/chain.rb:132:in `invoke'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/processor.rb:51:in `block in process'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/processor.rb:104:in `stats'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/processor.rb:50:in `process'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/celluloid-0.17.2/lib/celluloid/calls.rb:28:in `public_send'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/celluloid-0.17.2/lib/celluloid/calls.rb:28:in `dispatch'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/celluloid-0.17.2/lib/celluloid/call/async.rb:7:in `dispatch'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/celluloid-0.17.2/lib/celluloid/cell.rb:50:in `block in dispatch'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/celluloid-0.17.2/lib/celluloid/cell.rb:76:in `block in task'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/celluloid-0.17.2/lib/celluloid/actor.rb:339:in `block in task'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/celluloid-0.17.2/lib/celluloid/task.rb:44:in `block in initialize'
09:39:28 worker.1 | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/celluloid-0.17.2/lib/celluloid/task/fibered.rb:14:in `block in create'
Bundler could not find compatible versions for gem "sidekiq":
In Gemfile:
sidekiq
apartment-sidekiq (= 1.2.0) was resolved to 1.2.0, which depends on
sidekiq (>= 2.11)
capistrano-sidekiq was resolved to 1.0.3, which depends on
sidekiq (>= 3.4, < 6.0)
Apartment sidekiq is no longer working out of the box with the new Rails.
In order to make it work I had to manually invoke:
require 'apartment/sidekiq/railtie'
Apartment::Sidekiq::Middleware.run
I just got the following while trying to update to Apartment 2.0:
Bundler could not find compatible versions for gem "apartment":
In snapshot (Gemfile.lock):
apartment (= 2.0.0)
In Gemfile:
apartment (~> 2.0)
apartment-sidekiq (= 1.1.0) was resolved to 1.1.0, which depends on
apartment (~> 1.0)
I should add that I got this after a successful bundle update
BUT I noticed that apartment-sidekiq got reverted several versions: Installing apartment-sidekiq 0.1.0 (was 1.1.0)
That's because the current gemspec has spec.add_dependency 'apartment', '~> 1.0'
... perhaps that should now be spec.add_dependency 'apartment', '>= 1.0'
?
When running jobs that are firing multiple threads at a time, we keep getting: PG:ConnectionBad Connection is Closed
.
This occurs in Apartment's current
call (apartment-1.0.2/lib/apartment/adapters/abstract_adapter.rb:53), fired from previous_tenant = current
in the switch
call.
I wonder if this is perhaps related to the fact that sidekiq closes all active connections after each job: sidekiq-3.5.0/lib/sidekiq/middleware/server/active_record.rb:6
, and then there's no connections left to for the Apartment call to check the current database...
`
Took me an hour to figure this one out because I was looking at code inside github instead of the code in my gems folder.
Any plans on getting this pushed out soon?
Thanks.
Having this error ActiveRecord::ConnectionNotEstablished: No connection pool with id primary found
using sidekiq with 5 threads and db pool size set to 10.
Anyone got same? Any tips to solve this?
Rails 5. Stack trace:
ActiveRecord::ConnectionNotEstablished: No connection pool with id primary found.
from active_record/connection_adapters/abstract/connection_pool.rb:876:in `retrieve_connection'
from active_record/connection_handling.rb:128:in `retrieve_connection'
from active_record/connection_handling.rb:91:in `connection'
from apartment/adapters/abstract_adapter.rb:53:in `current'
from apartment/adapters/abstract_adapter.rb:96:in `switch'
from apartment/sidekiq/middleware/server.rb:4:in `call'
from sidekiq/middleware/chain.rb:130:in `block in invoke'
from sidekiq/middleware/server/logging.rb:11:in `block in call'
from sidekiq/logging.rb:32:in `with_context'
from sidekiq/middleware/server/logging.rb:7:in `call'
from sidekiq/middleware/chain.rb:130:in `block in invoke'
from sidekiq/middleware/chain.rb:133:in `invoke'
from sidekiq/processor.rb:129:in `block in process'
from sidekiq/processor.rb:168:in `stats'
from sidekiq/processor.rb:128:in `process'
from sidekiq/processor.rb:80:in `process_one'
from sidekiq/processor.rb:68:in `run'
from sidekiq/util.rb:17:in `watchdog'
from sidekiq/util.rb:25:in `block in safe_thread'
I'm using
gem 'apartment', '~> 2.0'
gem 'apartment-sidekiq', github: 'tmster/apartment-sidekiq'
gem 'sidekiq', '~> 5.0.0'
ruby '2.4.2'
gem 'rails', '5.0.6'
gem 'activerecord-import', '~> 0.20.0'
I got a job that creates a batch of records on the sidekiq dashboard I get this information.
Job
BuildFooComponents
Extras
{"apartment"=>"other_tanent"}
Error Class
ActiveRecord::RecordNotUnique
Error Message
PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "foo_pkey" DETAIL: Key (id)=(3880) already exists. : INSERT INTO "foo"(column) VALUES (nextval('demo.foo_id_seq')
if you can see the tanent VALUES (nextval('demo.foo_id_seq')
is not the same from the extras "apartment"=>"other_tanent"
the job
class BuildFooComponents
include Sidekiq::Worker
def perform(components, section_id, project_id)
group_components=[]
...
FooComponent.import group_components
end
end
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.