我有一个使用Sidetiq的重复选项安排在每天1200小时运行的Sidekiq工作服务器,当该工作服务器启动时,我总是以工作服务器连接到错误的地址来连接到错误的数据库服务器,该服务器的IP在我的config/database.yml
中不存在。
正确的URL是连接到mysqluser:mysql-database-ip
,但它连接到mysqluser:ip-address
下面是文件的配置。请让我知道我在做什么错?
database.yml
production:
adapter: mysql2
database: database2connect
username: mysqluser
password: <%= ENV['mysql_password'] %>
host: mysql-database-ip
pool: 25
socket: /var/run/mysqld/mysqld.sock
Sidekiq初始化程序文件
Sidekiq.configure_server do |config|
config.redis = { url: "redis://:#{ENV['redis_password']}@localhost:96526" }
end
Sidekiq.configure_client do |config|
config.redis = { url: "redis://:#{ENV['redis_password']}@localhost:96526" }
end
Sidekiq YML文件
:verbose: true
:pidfile: ./tmp/pids/sidekiq.pid
production:
:logfile: ./log/sidekiq.log
development:
:logfile: ./log/sidekiq.dev.log
:concurrency: 5
Sidekiq Worker
class MySidekiqWorker
include Sidekiq::Worker
include Sidetiq::Schedulable
sidekiq_options({
# Should be set to true (enables uniqueness for async jobs)
# or :all (enables uniqueness for both async and scheduled jobs)
unique: :all,
retry: 5,
raise_error: true
})
recurrence backfill: true do
daily.hour_of_day(12)
end
def perform(last_occurrence, current_occurrence)
billing_cycle_users = MySQLTable.where("parameter_1 <= ? AND parameter_1 >= ?", param1, param2) #Fails here!!!!
end
end
错误日志
"class"=>"MySidekiqWorker", "args"=>[1458129600.0, 1458199815], "retry"=>5, "queue"=>"default", "unique"=>"all", "raise_error"=>true, "jid"=>"bb2bce00baff05439c997a4e", "created_at"=>1458199815.0152047, "enqueued_at"=>1458200862.463864, "error_message"=>"Access denied for user 'mysqluser'@'ip-address' (using password: NO)", "error_class"=>"Mysql2::Error", "failed_at"=>1458199815.076714, "retry_count"=>5, "retried_at"=>1458200862.4711788}
2016-03-17T07:47:42.472Z 3427 TID-djcl0 WARN: Mysql2::Error: Access denied for user 'mysqluser'@'ip-address' (using password: NO)
2016-03-17T07:47:42.472Z 3427 TID-djcl0 WARN: /usr/local/rvm/gems/ruby-2.0.0-p353/gems/mysql2-0.3.20/lib/mysql2/client.rb:70:in `connect'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/mysql2-0.3.20/lib/mysql2/client.rb:70:in `initialize'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_handling.rb:53:in `connection'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/sanitization.rb:128:in `replace_bind_variables'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/sanitization.rb:115:in `sanitize_sql_array'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/sanitization.rb:26:in `sanitize_sql_for_conditions'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/relation/query_methods.rb:899:in `build_where'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/relation/query_methods.rb:545:in `where!'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/relation/query_methods.rb:535:in `where'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/querying.rb:9:in `where'
/home/project/app/workers/my_sidekiq_worker.rb:17:in `perform'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/processor.rb:151:in `execute_job'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/processor.rb:133:in `block (2 levels) in process'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/middleware/chain.rb:127:in `block in invoke'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-middleware-0.3.0/lib/sidekiq-middleware/server/unique_jobs.rb:11:in `call'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidetiq-0.7.0/lib/sidetiq/middleware/history.rb:18:in `call_with_sidetiq_history'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidetiq-0.7.0/lib/sidetiq/middleware/history.rb:6:in `call'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/middleware/server/active_record.rb:6:in `call'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/middleware/server/retry_jobs.rb:74:in `call'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/middleware/server/logging.rb:11:in `block in call'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/logging.rb:31:in `with_context'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/middleware/server/logging.rb:7:in `call'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/middleware/chain.rb:132:in `call'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/middleware/chain.rb:132:in `invoke'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/processor.rb:128:in `block in process'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/processor.rb:167:in `stats'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/processor.rb:127:in `process'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/processor.rb:79:in `process_one'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/processor.rb:67:in `run'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/util.rb:16:in `watchdog'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-4.1.1/lib/sidekiq/util.rb:24:in `block in safe_thread'
仅在我的sidekiq.rb
初始化文件中执行以下配置时才有效!但是,sidekiq不会从database.yml
那里接走吗?
Sidekiq.configure_server do |config|
config.redis = { url: "redis://:#{ENV['redis_password']}@localhost:96526" }
ActiveRecord::Base.establish_connection(
{ :adapter => 'mysql2',
:database => ' database2connect',
:host => 'mysql-database-ip',
:username => 'mysqluser',
:password => 'somepassword' }
)
end
Sidekiq.configure_client do |config|
config.redis = { url: "redis://:#{ENV['redis_password']}@localhost:96526" }
end
请杀死并重新启动sidekiq。它对我有用。