简体   繁体   English

Rails 5 sidekiq工作继续引用旧类

[英]rails 5 sidekiq jobs keep referencing old class

At first I had a class CastingMailer with a method email_coupon_sent, I created the class CouponMailer with everything that mailer needs and I put the method email_coupon_sent in that class, in my job I call CouponMailer.email_coupon_sent and sidekiq tells me in the log 2017-02-14T15:42:05.066Z 7344 TID-ynsk0 WARN: NoMethodError: undefined method `email_coupon_sent' for CastingMailer:Class, why sidekiq keep looking for email_coupon_sent in CastingMailer class. 最初,我有一个CastingMailer类,其方法为email_coupon_sent,创建了类CouponMailer,其中包含了mailer所需的所有内容,然后将方法email_coupon_sent放入该类中,在我的工作中,我称为CouponMailer.email_coupon_sent,sidekiq在日志2017-02中告诉了我-14T15:42:05.066Z 7344 TID-ynsk0警告:NoMethodError:CastingMailer:Class的未定义方法`email_coupon_sent',为什么sidekiq继续在CastingMailer类中寻找email_coupon_sent。

Code

admin_controller.rb admin_controller.rb

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

coupon_sent_job.rb 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 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 意见/ coupon_mailer

email_coupon_sent.html.erb
email_coupon_sent.text.erb

sidekiq.log 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'

in my CastingMailer currently there is not email_coupon_sent method 在我的CastingMailer中,目前没有email_coupon_sent方法

Thanks in advance. 提前致谢。

The job saves the class and method name it needs to call. 作业将保存需要调用的类和方法名称。 You can't just rename a class if there are jobs that still reference it in Redis. 如果有些作业仍在Redis中引用它,则不能重命名。 You have to ensure there are no more jobs referencing the name too. 您必须确保不再有引用该名称的作业。 Easiest thing to do is flush the entire Redis database but that wipes out everything. 最简单的方法是刷新整个Redis数据库,但这会清除所有内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM