【问题标题】:rails 5 sidekiq jobs keep referencing old classrails 5 sidekiq 工作继续引用旧类
【发布时间】:2017-02-15 06:35:12
【问题描述】:

起初我有一个带有方法 email_coupon_sent 的 CastingMailer 类,我创建了带有邮件程序需要的所有东西的 CouponMailer 类,然后我将方法 email_coupon_sent 放在该类中,在我的工作中我调用 CouponMailer.email_coupon_sent,sidekiq 在日志中告诉我2017-02-14T15:42:05.066Z 7344 TID-ynsk0 WARN: NoMethodError: undefined method `email_coupon_sent' for CastingMailer:Class,为什么 sidekiq 一直在 CastingMailer 类中寻找 email_coupon_sent。

代码

admin_controller.rb

@coupon.give!
CouponSentJob.perform_later(@user.profileable, @coupon)

coupon_sent_job.rb

def perform(profile, coupon)
  # Send coupon to user
  Notification.notify_coupon_sent(profile, coupon)
  CouponMailer.email_coupon_sent(profile, coupon).deliver_now
end

coupon_mailer.rb

def email_coupon_sent(profile, coupon)
  @profile = profile
  @coupon = coupon
  mail(to: @profile.user.email, subject: I18n.t('views.mailers.coupon.coupon_sent.subject'))
end

views/coupon_mailer

email_coupon_sent.html.erb
email_coupon_sent.text.erb

sidekiq.log

2017-02-14T15:42:04.980Z 7344 TID-ynsk0 CouponSentJob JID-0b611e12bcd38bd3fc87b86c INFO: start
2017-02-14T15:42:05.065Z 7344 TID-ynsk0 CouponSentJob JID-0b611e12bcd38bd3fc87b86c INFO: fail: 0.085 sec
2017-02-14T15:42:05.066Z 7344 TID-ynsk0 WARN: {"context":"Job raised exception","job":       {"class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper","wrapped":"CouponSentJob","queue":"default","args":   [{"job_class":"CouponSentJob","job_id":"d6f830a6-db9f-4af8-bb0c-83580536a8db","queue_name":"default","priority":null,"arguments":  [{"_aj_globalid":"gid://cubamodela/ProfileModel/4"},{"_aj_globalid":"gid://cubamodela/Coupon/6"}],"locale":"en"}  ],"retry":true,"jid":"0b611e12bcd38bd3fc87b86c","created_at":1487086924.9707098,"enqueued_at":1487086924.9742587,"error_message":"undefined   method `email_coupon_sent' for     CastingMailer:Class","error_class":"NoMethodError","failed_at":1487086925.0644813,"retry_count":0},"jobstr":"{\"class\":  \"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper\",\"wrapped\":\"CouponSentJob\",\"queue\":\"default\",\"args\":[{\"job_class\":  \"CouponSentJob\",\"job_id\":\"d6f830a6-db9f-4af8-bb0c-83580536a8db\",\"queue_name\":\"default\",\"priority\":null,\"arguments\":  [{\"_aj_globalid\":\"gid://cubamodela/ProfileModel/4\"},{\"_aj_globalid\":\"gid://cubamodela/Coupon/6\"}],\"locale\":\"en\"}],\"retry\":true,  \"jid\":\"0b611e12bcd38bd3fc87b86c\",\"created_at\":1487086924.9707098,\"enqueued_at\":1487086924.9742587}"}
2017-02-14T15:42:05.066Z 7344 TID-ynsk0 WARN: NoMethodError: undefined method `email_coupon_sent' for CastingMailer:Class
2017-02-14T15:42:05.066Z 7344 TID-ynsk0 WARN: /home/deployer/.rvm/gems/ruby-2.3.1/gems/actionmailer-5.0.1/lib/action_mailer/base.rb:565:in   `method_missing'
/home/deployer/cubamodela/app/jobs/coupon_sent_job.rb:6:in `perform'
/home/deployer/.rvm/gems/ruby-2.3.1/gems/activejob-5.0.1/lib/active_job/execution.rb:34:in `block in perform_now'
/home/deployer/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:126:in `call'

在我的 CastingMailer 中目前没有 email_coupon_sent 方法

提前致谢。

【问题讨论】:

  • 你是生产环境还是开发环境?进行更改后,您是否重新启动了 sidekiq?

标签: ruby-on-rails actionmailer sidekiq jobs


【解决方案1】:

作业保存它需要调用的类和方法名。如果 Redis 中仍有作业引用它,则不能只重命名一个类。您必须确保也没有更多工作引用该名称。最简单的做法是刷新整个 Redis 数据库,但这会清除所有内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-03
    • 2018-08-29
    • 1970-01-01
    • 2019-06-03
    • 1970-01-01
    • 1970-01-01
    • 2014-07-31
    • 2017-12-21
    相关资源
    最近更新 更多