- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在尝试在生产环境中发送邮件,但它抛出 Activejob 反序列化错误。sidekiq 在后台运行。我添加了sidekiq gem。我在 comment_notification.rb 中写了一个方法来向用户发送电子邮件。然后在创建操作的 Controller 中我添加了这个
def create
CommentNotification.send_comment_mail(@current_user).deliver_later(wait: 1.minute)
end
def send_comment_email(current_user)
mail( to: current_user.email,
:subject => "commented on post",
:from => "<noreply@xxx.com>")
end
它在本地服务器上工作正常,但在生产中我收到这个错误
/home/apps/commentpost/shared/bundle/ruby/2.3.0/gems/sidekiq-4.2.3/lib/sidekiq/processor.rb:69:in `run'
/home/apps/commentpost/shared/bundle/ruby/2.3.0/gems/sidekiq-4.2.3/lib/sidekiq/util.rb:17:in `watchdog'
/home/apps/commentpost/shared/bundle/ruby/2.3.0/gems/sidekiq-4.2.3/lib/sidekiq/util.rb:25:in `block in safe_thread'
2016-11-18T06:47:16.162Z 19093 TID-uw66g ActionMailer::DeliveryJob JID-e56b150964abf082e78089d9 INFO: start
2016-11-18T06:47:16.167Z 19093 TID-uw66g ActionMailer::DeliveryJob JID-e56b150964abf082e78089d9 INFO: fail: 0.005 sec
2016-11-18T06:47:16.167Z 19093 TID-uw66g WARN: {"context":"Job raised exception","job":{"class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper","wrapped":"ActionMailer::DeliveryJob","queue":"mailers","args":[{"job_class":"ActionMailer::DeliveryJob","job_id":"96e06bc6-1380-47b9-9393-9727868b3897","queue_name":"mailers","priority":null,"arguments":["CommentNotification","send_comment_email","deliver_later",{"_aj_globalid":"gid://commentpost/comment/40"},{"_aj_globalid":"gid://commentpost/User/20"}],"locale":"en"}],"retry":true,"jid":"e56b150964abf082e78089d9","created_at":1479450405.8364522,"enqueued_at":1479451636.1602836,"error_message":"Error while trying to deserialize arguments: Couldn't find Comment with 'id'=40","error_class":"ActiveJob::DeserializationError","failed_at":1479450405.8429642,"retry_count":6,"retried_at":1479451636.1668367},"jobstr":"{\"class\":\"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper\",\"wrapped\":\"ActionMailer::DeliveryJob\",\"queue\":\"mailers\",\"args\":[{\"job_class\":\"ActionMailer::DeliveryJob\",\"job_id\":\"96e06bc6-1380-47b9-9393-9727868b3897\",\"queue_name\":\"mailers\",\"priority\":null,\"arguments\":[\"CommentNotification\",\"send_comment_email\",\"deliver_later\",{\"_aj_globalid\":\"gid://commentpost/comment/40\"},{\"_aj_globalid\":\"gid://commentpost/User/20\"}],\"locale\":\"en\"}],\"retry\":true,\"jid\":\"e56b150964abf082e78089d9\",\"created_at\":1479450405.8364522,\"enqueued_at\":1479451636.1602836,\"error_message\":\"Error while trying to deserialize arguments: Couldn't find Comment with 'id'=40\",\"error_class\":\"ActiveJob::DeserializationError\",\"failed_at\":1479450405.8429642,\"retry_count\":5,\"retried_at\":1479450981.998904}"}
2016-11-18T06:47:16.167Z 19093 TID-uw66g WARN: ActiveJob::DeserializationError: Error while trying to deserialize arguments: Couldn't find Comment with 'id'=40
2016-11-18T06:47:16.167Z 19093 TID-uw66g WARN: /
有人可以帮我解决这个问题吗?为此,我将不胜感激。
最佳答案
据我正确理解, Controller 中的 create
方法也创建评论并发送新创建评论的电子邮件?
那这里用回调比较好。
我们在我们的项目中遇到了同样的问题,我们通过使用类似的东西解决了它:
# in model
after_commit :send_mail, on: :create
private
def send_mail
CommentNotification.send_comment_mail(campaign.user).deliver_later
end
然后您可以确定在邮件投递之前该记录确实存在于数据库中。
这里的问题是,您运行 Comment#create
并将邮件放入 Controller 中。现在 Sidekiq 会在 Rails 提交新评论之前运行任务。
然后你就会得到这个错误。
问候,
温泉
关于ruby - ActiveJob::DeserializationError:尝试反序列化参数时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40672232/
我正在尝试使用Sidekiq来运行以下作业。 该作业在未排队(perform_now)时表现良好,但在使用(Sidekiq)称为(perform_later)时失败。 AddEmployeesToRo
我正在尝试在生产环境中发送邮件,但它抛出 Activejob 反序列化错误。sidekiq 在后台运行。我添加了sidekiq gem。我在 comment_notification.rb 中写了一个
在 Rails 6 应用程序中,我有以下代码。 class Reservation < ApplicationRecord after_create :publish_creation
我正在将 Rails 应用程序从 3.2 升级到 4.x。我现在通过我的测试得到以下乱七八糟的东西。 Delayed::DeserializationError: Job failed to l
我是一名优秀的程序员,十分优秀!