brandonhilkert / sucker_punch

Sucker Punch is a Ruby asynchronous processing library using concurrent-ruby, heavily influenced by Sidekiq and girl_friday.
MIT License
2.65k stars 114 forks source link

ActiveRecord::StatementInvalid PG::Error invalid valude for parameter client_min_messages #186

Closed nynhex closed 7 years ago

nynhex commented 7 years ago

I have a worker which I can easily fire off from the rails console and it will work without fail. However when I run this in staging (production copy) via a rake task I get the following stack trace:

Sucker Punch job error for class: 'ControlledSubstanceAutoDenyJob' args: []
ActiveRecord::StatementInvalid PG::Error: ERROR:  invalid value for parameter "client_min_messages": ""
HINT:  Available values: debug5, debug4, debug3, debug2, debug1, log, notice, warning, error.
: SET client_min_messages TO ''
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `async_exec'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `block in execute'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.22.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/postgresql_adapter.rb:649:in `execute'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/postgresql_adapter.rb:902:in `client_min_messages='
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/postgresql_adapter.rb:387:in `ensure in set_standard_conforming_strings'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/postgresql_adapter.rb:387:in `set_standard_conforming_strings'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/postgresql_adapter.rb:1242:in `configure_connection'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/postgresql_adapter.rb:1229:in `connect'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/postgresql_adapter.rb:324:in `initialize'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
/home/deploy/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
/home/deploy/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.22.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection'
/home/deploy/myapp/releases/20160927182842/app/jobs/controlled_substance_auto_deny_job.rb:6:in `perform'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/sucker_punch-2.0.2/lib/sucker_punch/job.rb:54:in `__run_perform'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/sucker_punch-2.0.2/lib/sucker_punch/job.rb:36:in `block in perform_async'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/concurrent-ruby-1.0.2/lib/concurrent/executor/ruby_thread_pool_executor.rb:348:in `call'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/concurrent-ruby-1.0.2/lib/concurrent/executor/ruby_thread_pool_executor.rb:348:in `run_task'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/concurrent-ruby-1.0.2/lib/concurrent/executor/ruby_thread_pool_executor.rb:337:in `block (3 levels) in create_worker'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/concurrent-ruby-1.0.2/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `loop'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/concurrent-ruby-1.0.2/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `block (2 levels) in create_worker'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/concurrent-ruby-1.0.2/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `catch'
/home/deploy/myapp/shared/bundle/ruby/1.9.1/gems/concurrent-ruby-1.0.2/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `block in create_worker'

So I looked this up, and adjusted my database.yml to include min_messages: warning in the production yaml block and the exception went away. However whenever I fire the job from a rake task it silently fails with no stack trace.

Here's how I'm running it in production:

RAILS_ENV=production bundle exec rake controlled_substance:auto_deny

And here's what my rake task looks like

namespace :controlled_substance do
  desc "Auto-deny any pending controlled substance report after 48 hours" #task describtion
  task :auto_deny => :environment do
     auto_deny
  end

  def auto_deny
    ControlledSubstanceAutoDenyJob.new.async.perform
  end
end

Am I not able to run sucker_punch jobs from a rake task or am I totally missing something here?

Thanks in advance on this.

brandonhilkert commented 7 years ago

Sounds like the rake process is starting, queueing the jobs and then killing the process. In that case, the threads die too, so nothing is done. To confirm, you can add a sleep to the end of the rake task. If that job runs successfully then, that's your problem.

nynhex commented 7 years ago

@brandonhilkert thanks so much, I injected 2 seconds of sleep and the job ran via rake no problem. Thanks so much for the quick response. I love sucker_punch but am just getting used to making it do things it may not have been designed to do 👍