deliver_later using sidekiq rails

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



deliver_later using sidekiq rails



I tried to do deliver_later using sidekiq, but I got a error message.



Here is my setup


* execute redis
redis-server

* execute sidekiq
bundle exec sidekiq -q default -q mailers

* Gemfile
gem 'sidekiq'


* application.rb
config.active_job.queue_adapter = :sidekiq


#send email
UserMailer.account_activation(@user).deliver_later



I have no idea how to resolve the problem.
Here is error message


50.345Z 41513 TID-oxh5ccnb8 ActionMailer::DeliveryJob JID-1c7ea4b33150d3805ff777aa INFO: start
2016-11-18T17:13:50.413Z 41513 TID-oxh5ccnb8 ActionMailer::DeliveryJob JID-1c7ea4b33150d3805ff777aa INFO: fail: 0.068 sec
2016-11-18T17:13:50.414Z 41513 TID-oxh5ccnb8 WARN: "context":"Job raised exception","job":"class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper","wrapped":"ActionMailer::DeliveryJob","queue":"mailers","args":["job_class":"ActionMailer::DeliveryJob","job_id":"c2ee4092-4e73-4e1f-857f-3e081594c735","queue_name":"mailers","priority":null,"arguments":["UserMailer","account_activation","deliver_now","_aj_globalid":"gid://academic-lib/User/8"],"locale":"en"],"retry":true,"jid":"1c7ea4b33150d3805ff777aa","created_at":1479489230.323255,"enqueued_at":1479489230.3232949,"error_message":"No route matches :action=>"edit", :controller=>"account_activations", :email=>"chandleryang76@gmail.com", :id=>nil missing required keys: [:id]","error_class":"ActionView::Template::Error","failed_at":1479489230.4132302,"retry_count":0,"jobstr":""class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper","wrapped":"ActionMailer::DeliveryJob","queue":"mailers","args":["job_class":"ActionMailer::DeliveryJob","job_id":"c2ee4092-4e73-4e1f-857f-3e081594c735","queue_name":"mailers","priority":null,"arguments":["UserMailer","account_activation","deliver_now","_aj_globalid":"gid://academic-lib/User/8"],"locale":"en"],"retry":true,"jid":"1c7ea4b33150d3805ff777aa","created_at":1479489230.323255,"enqueued_at":1479489230.3232949"
2016-11-18T17:13:50.414Z 41513 TID-oxh5ccnb8 WARN: ActionView::Template::Error: No route matches :action=>"edit", :controller=>"account_activations", :email=>"chandleryang76@gmail.com", :id=>nil missing required keys: [:id]
2016-11-18T17:13:50.414Z 41513 TID-oxh5ccnb8 WARN: /Users/chandler/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.0.1/lib/action_dispatch/journey/formatter.rb:50:in `generate'
/Users/chandler/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/route_set.rb:629:in `generate'
/Users/chandler/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/route_set.rb:660:in `generate'
/Users/chandler/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/route_set.rb:707:in `url_for'




4 Answers
4



This is the error



2016-11-18T17:13:50.414Z 41513 TID-oxh5ccnb8 WARN: ActionView::Template::Error: No route matches :action=>"edit", :controller=>"account_activations", :email=>"chandleryang76@gmail.com", :id=>nil missing required keys: [:id]



Your mailer view is erroring out. Somewhere there you have something like this


edit_account_activation_path(@activation)



where @activation is nil. Hence the error. Edit path is not valid without an object.


@activation



There is error in mailer view.
You need to check @activation object which is passing as nil.



If you are working with sidekiq don't use deliver later because the job never performs, instead use perform_in(<>) and call a worker with the method deliver_now inside





deliver_later should work with sidekiq as long as sidekiq's configured for active jobs (config.active_job.queue_adapter = :sidekiq - gist.github.com/maxivak/690e6c353f65a86a4af9).
– mahemoff
Aug 6 at 9:03



config.active_job.queue_adapter = :sidekiq



I guess you follow the book《ruby on rails tutorial》, if we run the code with deliver_now, the result will correct, but if we run the code with deliver_later, the error top will show.
After reading active job guides, i know active job use GlobalID, which makes it possible to pass live Active Record objects to your job instead of class/id pairs.



In the book 《ruby on rails tutorial》, the attribute activation_token is virtual attribute


class User < ApplicationRecord
attr_accessor :activation_token
end



active job use user object as argument, user object will be sent as excepted, but the virtual attribute will lost, the methods are as follows:


class UserMailer < ApplicationMailer
def account_activation(user, activation_token)
@user = user
@activation_token = activation_token
mail to: user.email, subject: "user activation"
end
end

UserMailer.account_activation(user, user.activation_token).deliver_later

<p><%= link_to "active link", edit_account_activation_url(@activation_token, email: @user.email) %></p>






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered