我在heroku上使用resque / redis来发送电子邮件作为后台工作。它适用于我发送的第一封电子邮件,但之后我得到错误:(ActiveRecord :: StatementInvalid:PG ::错误:SSL错误:解密失败或错误记录mac :) ...
我已经看到了添加到初始化程序中的其他问题/答案:
Resque.after_fork = Proc.new {ActiveRecord :: Base.establish_connection} OR
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工作人员。正如我所说,第一封电子邮件发送无错误,然后在收到上述错误后发送任何电子邮件。
提前致谢! 麦克
答案 0 :(得分:0)
好的,所以无法解决这个问题......
切换到延迟工作并且工作得更好。有点令人沮丧的是我不能再用apn_sender发送推送通知,但apn_on_rails工作正常。
奇怪的问题,仍然好奇......