我在 heroku 上使用 resque/redis 将电子邮件作为后台作业发送。它适用于我发送的第一封电子邮件,但之后我收到错误:(ActiveRecord::StatementInvalid: PG::Error: SSL error: decryption failed or bad record mac :) ...
我已经看到了其他要添加到初始化程序的问题/答案:
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection } 或
Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
但是,我已经这样做了(并尝试了我能想到的任何其他事情),但我仍然遇到同样的错误。我只用 before_fork 和 after_fork 运行代码无济于事。
我还使用 APN_sender 发送苹果推送通知。这些工作人员没有任何问题(但我称默认的 Heroku 工作人员来做这些工作,而不是 Resque 工作人员)。
这是我的相关文件,请帮忙!这也是我的第一个 SO 问题。如果做得不完美,请道歉。
#config/resque.rb
after_fork do |server, worker, resque|
logger.info("Got to after_fork in resque.rb config file")
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
--------------------
#config/initializers/resque.rb
require 'resque'
require 'resque/server'
heroku_environments = ["staging", "production"]
rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..'
rails_env = ENV['RAILS_ENV'] || 'development'
#confusing wording.. determines whether or not we are in Production, tested and working
unless heroku_environments.include?(rails_env)
resque_config = YAML.load_file(rails_root + '/config/resque.yml')
Resque.redis = resque_config[rails_env]
else
uri = URI.parse(ENV["REDISTOGO_URL"] || "redis://localhost:6379/")
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
end
----------------------
#resque.rake
require 'resque/tasks'
task "resque:setup" => :environment do
ENV['QUEUE'] = '*'
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }
Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
end
task "apn:setup" => :environment do
ENV['QUEUE'] = '*'
end
desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"
desc "Alias for apn:work (To run workers on Heroku)"
task "jobs:work" => "apn:work"
-----------------------
#Sending the email
@event.guests.each do |g|
Resque.enqueue(MailerCallback, "Notifier", :time_change, @event.id, g.id)
end
我正在从 Heroku ps:scale 命令运行一名 Heroku 工作人员和一名 Resque 工作人员。正如我所说,第一封电子邮件发送无错误,然后收到上述错误后的任何电子邮件。
提前致谢!麦克风