邮箱上的邮戳邮寄和登台问题

问题描述 投票:0回答:1

在我配置使用postmark服务发布电子邮件后,我面临着与developmentstaging envs的一些麻烦。

简短说明:portmark在以下情况下使用'ok'工作正常,当有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网址,指向错误页面。

最有趣的是,在我从开发或登台envs控制台发送电子邮件后,我打开了sidekiq仪表板,我发现当生产中没有用户ID与要求发送此电子邮件的ID相关联时(来自其他envs),这封邮件失败了这条消息:

安慰:

> 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

Obs:所有三种环境都使用不同的邮戳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:

我还试图去过邮件工作的过去的分支机构,没有(我重新启动服务器)...

ruby-on-rails sidekiq postmark
1个回答
0
投票

这是一个部分解决方案,可以在我的案例中使用测试环境上的邮件。

关于主题10.2的rails mailing documentation反序列化说:

如果在作业入队后但在调用#perform方法之前删除了传递的记录,则Active Job将引发ActiveJob :: DeserializationError异常。

所以我意识到,在发送方法(deliver_later)采取行动之前,记录已经从缓存中删除了。如果只在developmentstaging环境中进行,那么我附上:

production.rb

config.active_job.queue_adapter = :sidekiq

development.rb / staging.rb

  config.active_job.queue_adapter = :inline
© www.soinside.com 2019 - 2024. All rights reserved.