2016-11-18 4 views
4

프로덕션 환경에서 메일을 보내려고 시도 중이지만 Activejob deserailization을 던지고 있습니다. error.sidekiq가 백그라운드에서 실행 중입니다. 사이드 킥 보석을 추가했습니다. comment_notification.rb에 사용자에게 전자 메일을 보내기위한 한 가지 방법을 썼습니다. 그런 다음 동작을 만들 수있는 컨트롤러에서 나는 그것은 로컬 서버에서 잘 작동 한이ActiveJob :: DeserializationError : 인수를 deserialize하려고 시도하는 중 오류가 발생했습니다.

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 => "<[email protected]>") 
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:/

이 사람이 의심의 여지에 대한 좀 도와 주 시겠어요이 오류는 무엇입니까? 이것을 위해 나는 감사 할 것이다.

+0

오류를 기록 할 때, 인수를 역 직렬화하는 동안 ', 오류를 특히이 부분을 읽어 :'ID '= 40'에 코멘트 찾을 수 없습니다. 문제 해결에 대한 힌트를주지 않습니까? –

+0

ID가 40 인 데이터베이스에 ID가 있으며 주석도 작성 중입니다. 유일한 문제는 메일이 트리거되지 않는 것입니다. – asha

답변

5

컨트롤러에서 정확하게 create 메서드를 사용하면 주석이 만들어지고 새로 작성된 주석에 대한 전자 메일이 전송됩니까?

그런 다음 여기에 콜백을 사용하는 것이 좋습니다.
우리는 우리의 프로젝트에 같은 문제를했고 우리는 같은 것을 사용하여 그것을 해결 :

# in model 
after_commit :send_mail, on: :create 

private 

def send_mail 
    CommentNotification.send_comment_mail(campaign.user).deliver_later 
end 

는 그런 다음 메일이 전달되기 전에 레코드가 실제로 데이터베이스에 있는지 확신 할 수 있습니다.

여기서 문제는 Comment#create을 실행하고 컨트롤러에 메일을 대기열에 넣는 것입니다. 이제 Rails가 새로운 주석을 작성하기 전에 Sidekiq이 작업을 수행 할 수 있습니다.
그리고 정확히이 오류가 발생합니다.

감사합니다,
스파 지금

+0

컨트롤러로 쓸 수 있습니까? 예 : after_action : 이메일 보내기 전용 : [: create] – asha

+1

수 있습니다. 하지만 'CommentNotification.send_comment_mail (campaign.user) .deliver_later (wait : 5minutes)'또는 그와 비슷한 것을 사용해야합니다. after_commit과 위의 메소드 모두에 대한 – Spa

+0

이 작동하지 않습니다. 여전히 같은 오류를 보여줍니다. – asha