Poison EncodeError无法编码值。 Verk包

时间:2017-05-21 11:38:28

标签: elixir phoenix-framework

我正在尝试使用凤凰框架构建一个简单的邮件程序应用程序,我需要发送非阻止的电子邮件。为此,我决定使用Verk包。

问题是当我将广告系列对象传递给Verk.enqueue时,我收到以下错误。

Poison.EncodeError at POST /1/send
unable to encode value: {nil, "campaigns"}

-

  def send(conn, %{"id" => id}) do
    campaign = Repo.get!(Campaign, id) |> Repo.preload(group: :users)


    Verk.enqueue(%Verk.Job{queue: :default,
                           class: "EmailWorker", args: [campaign], max_retry_count: 5})
  end

以下作品,但我必须等待几秒才能完成。

Enum.each(campaign.group.users, fn(user) ->
  Email.campaign_email(campaign, user) |> Mailer.deliver_later()
end)

如果我添加

  @derive {Poison.Encoder, only: [:name, :subject, :body]}

这是终端日志中发生的事情

[info] EmailWorker 3874693212000703845 start
[debug] Job failed reason: %KeyError{key: :group, term: %{"body" => "<h1>Hello</h1>\r\n\r\n<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>\r\n\r\n<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>", "name" => "Lorem ipsum dolor sit amet, consectetur adipisicing elit", "subject" => "Lorem ipsum dolor sit amet"}}

0 个答案:

没有答案