【问题标题】:Mandrill / Mailchip Devise email works with mandrill_send but fails with SidekiqMandrill / Mailchip 设计电子邮件与 mandrill_send 一起使用,但与 Sidekiq 一起失败
【发布时间】:2016-06-05 23:05:41
【问题描述】:

我是 Mandrill 的新手,所以这可能是我的问题的根本原因 :) - 我从这个例子中得到了它:

https://nvisium.com/blog/2014/10/08/mandrill-devise-and-mailchimp-templates/

我不认为这是一个设计问题,但我想我会提到它。这是我的 DeviseMailer 代码:

  def invitation_instructions(record, token, opts={})
    options = {
      :subject => "Subject",
      :from_name=> "From",
      :email => record.email,
      :global_merge_vars => [
        { name: 'invite_name', content: "Invited By" },
        { name: 'invite_email', content: "Invited By Email" },
        { name: 'invite_company', content: "Company Name" },
        { name: 'invitation_url', content: root_url(:invitation_token => token) } #accept_invitation_url(record, :invitation_token => token)
      ],
      :template => "Invitation",
      :template_name => "Invitation"
    }
    mandrill_send options
    #MandrillEmail.perform_async(options)
  end

  def mandrill_send(opts={})
    message = { 
      :subject=> "#{opts[:subject]}", 
      :from_name=> "#{opts[:from_name]}",
      :from_email=>"do-not-reply@xxxxx.com",
      :to=>
            [{"email"=>"#{opts[:email]}",
                "type"=>"to"}],
      :global_merge_vars => opts[:global_merge_vars]
      }
    sending = MANDRILL.messages.send_template opts[:template], [], message
    rescue Mandrill::Error => e
      Rails.logger.debug("#{e.class}: #{e.message}")
      raise
  end

这行得通 - 我收到了我的电子邮件和模板工作等。

现在,如果我将逻辑移至 SideKiq 工作器 (MandrillEmail.perform_async(options)),它会失败并显示:

Mandrill::ValidationError: Validation error: {"template_name":"Sorry, this field can't be left blank.","message":{"to":[{"email":"Sorry, this field can't be left blank."}]}}

我添加了:template_name => "Invitation",但这不起作用。我的 sidekiq 监视器清楚地显示了 template_name 和 message>to>email: 参数正在传递给 worker。

不确定我在这里缺少什么。

【问题讨论】:

    标签: ruby-on-rails devise mailchimp sidekiq mandrill


    【解决方案1】:

    您可能遇到了字符串/符号冲突。符号不能传递给 Sidekiq 作业。

    https://github.com/mperham/sidekiq/wiki/Best-Practices#1-make-your-job-parameters-small-and-simple

    【讨论】:

    • 这是有道理的。我回家后会检查一下。我确定我之前已经阅读过该链接,我真的应该将所有逻辑移入工作程序并传递用户 ID。
    猜你喜欢
    • 2015-05-16
    • 1970-01-01
    • 2017-07-17
    • 2016-03-13
    • 2021-05-17
    • 1970-01-01
    • 2016-07-05
    • 2020-04-25
    相关资源
    最近更新 更多