postmark
服务发布电子邮件后,我在development
和staging
环境中遇到了一些麻烦。 简短的说明:在以下情况下,如果使用“ ok”,portmark可以很好地工作,并且当存在DeserializationError
时,活动作业似乎失败了,因为它正在查看是否用户ID存在于生产数据库中。
开发环境:
devise mailing -> ActiveJob::DeserializationError
deliver_later -> ActiveJob::DeserializationError
delover_now -> ok
登台环境
devise mailing -> ActiveJob::DeserializationError
deliver_later -> ActiveJob::DeserializationError
delover_now -> ok
生产环境
devise mailing -> ok
deliver_later -> ok
deliver_now -> ok
详细解释:
当我在这两个环境中并要求devise
进行确认指示时,它将发送一个带有production
URL的电子邮件链接,并带有指向错误页面的令牌。
最有趣的是,在我从开发或暂存环境控制台发送电子邮件后,我打开了sidekiq仪表板,发现在生产中没有与该电子邮件请求的ID相关的用户ID时, (从其他环境发送),此邮件发送失败并显示以下消息:
控制台:
> Rails.env
"development"
> @user.id
22
> UserMailer.welcome(@user).deliver_later
Sidekiq错误:
ActiveJob :: DeserializationError:尝试反序列化时出错 参数:找不到'id'= 22
的用户
控制台:
> Rails.env
"staging"
> @user.id
15
> UserMailer.welcome(@user).deliver_later
Sidekiq错误:
ActiveJob :: DeserializationError:尝试反序列化时出错 参数:找不到'id'= 15
的用户
一些配置:
Rails 5.0.1
postmark (1.14.0)
postmark-rails (0.18.0)
production.rb
...
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_token => ENV["POSTMARK_API_KEY"] }
config.action_mailer.default_url_options = { host: "www.mywebsite.com" }
...
development.rb
...
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_token => ENV["POSTMARK_API_KEY"] }
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
...
staging.rb
...
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_token => ENV["POSTMARK_API_KEY"] }
config.action_mailer.default_url_options = { host: "website.herokuapp.com" }
...
sidekiq.yml
:concurrency: 3
:timeout: 60
:verbose: true
:queues:
- default
- mailers
糟糕:这三种环境都使用不同的邮戳api密钥。
更新1
这里是发展:
development.rb
Rails.application.configure do
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_token => ENV["POSTMARK_API_KEY"] }
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.cache_classes = false
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled.
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800'
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
config.assets.precompile += %w( '.svg' )
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_caching = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Suppress logger output for asset requests.
config.assets.quiet = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end
我使用gmail更改为旧配置,问题仍然存在...
development.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.action_mailer.delivery_method = :letter_opener
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled.
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800'
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
config.assets.precompile += %w( '.svg' )
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_caching = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Suppress logger output for asset requests.
config.assets.quiet = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: 'gmail.com',
user_name: ENV['GMAIL_ADDRESS'],
password: ENV['GMAIL_APP_PASSWORD'],
authentication: "plain",
enable_starttls_auto: true
}
config.action_mailer.default_url_options = {host: "localhost:3000"}
end
更新2:
我还尝试过过去的邮件发送分支,但没有任何反应(我重新启动了服务器)...
答案 0 :(得分:0)
这是部分解决方案,可以在我的情况下在测试环境中使用邮件。
关于主题10.2反序列化的rails mailing documentation,说:
如果在入队后但在调用#perform方法之前删除已通过的记录,则“活动作业”将引发ActiveJob :: DeserializationError异常。
因此,我意识到在发送方法(deliver_later)起作用之前,已从缓存中删除了记录。如果这仅在development
和staging
环境中进行,那么我将附加在:
production.rb
config.active_job.queue_adapter = :sidekiq
development.rb / staging.rb
config.active_job.queue_adapter = :inline