我在heroku上使用resque/redis發送電子郵件作爲後臺作業。它適用於我發送的第一封電子郵件,但之後,我得到的錯誤:(ActiveRecord :: StatementInvalid:PG ::錯誤:SSL錯誤:解密失敗或壞的記錄mac :) ...Heroku上的Resque Workers被鎖定在Postgres DB SSL之外 - 還沒有修復
我已經看到的其他問題/答案是說添加到一個初始化:
Resque.after_fork = Proc.new {ActiveRecord的:: Base.establish_connection} OR
Resque.before_fork = Proc.new {的ActiveRecord :: Base.establish_connection}
但是,我已經做了這件事(並嘗試了任何我能想到的其他事情),我仍然是ge同樣的錯誤。我只用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 worker和一個Resque worker。正如我所說,第一封電子郵件發送無錯,然後在得到上述錯誤後發送任何電子郵件。
在此先感謝! 邁克
我讀到Resque不適合Postgres。我想我會嘗試延遲作業或隊列經典。 – Jirico